MVC4 WebApi中的DefaultCredentials选项和HTTPS?

时间:2012-10-20 17:51:19

标签: rest asp.net-mvc-4 https asp.net-web-api

我遇到DefaultCredentials选项和HTTPS问题。如果我使用HTTP协议一切正常 - ntlm授权是可以的,但如果我在Thread.CurrentPrincipal中的webservice端将HTTP更改为HTTPS,我什么都没有(空字符串和IsAuthenticate on false值)。 你有类似的问题吗?

我的Ntlm配置:

internal class NtlmSelfHostConfiguration : HttpSelfHostConfiguration
{
    public NtlmSelfHostConfiguration(string baseAddress) : base(baseAddress) { }

    public NtlmSelfHostConfiguration(Uri baseAddress) : base(baseAddress) { }

    protected override BindingParameterCollection OnConfigureBinding(HttpBinding httpBinding)
    {
        httpBinding.Security.Mode = HttpBindingSecurityMode.Transport;
        httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
        return base.OnConfigureBinding(httpBinding);
    }
}

创建HttpClient

var handler = new HttpClientHandler() { UseDefaultCredentials = true };
httpClient = new HttpClient(handler);

用户密码基本身份验证工作正常,因此证书没有问题

0 个答案:

没有答案