我有以下配置:
>自托管ASP.NET Web API
> ASP.NET MVC 3 Web应用程序
Web应用程序[2]通过HTTPS与Web API [1]通信.
他们(现在)都住在同一台机器上.
Web API [1]的Http绑定配置如下:
httpBinding.Security.Mode = HttpBindingSecurityMode.Transport;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
httpBinding.TransferMode = TransferMode.Streamed
我无法使用https和ntlm授权使其工作.
>如果我通过普通的http进行通信它是有效的,我已经过适当的身份验证
>如果我通过https进行通信,它会为所有具有[Authorize]标签的控制器操作提供“401 Unauthorized”错误(它适用于不需要授权的操作)
为什么仅更改传输协议(从http到https)会阻止NTLM身份验证工作?
感谢您的帮助!
最佳答案 @Jacek Nowak
我自己遇到了同样的问题,今天我刚刚遇到了以下
post中详述的答案.
以下是我编写代码的方法.
public 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.TransportCredentialOnly;
httpBinding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Ntlm;
httpBinding.ConfigureTransportBindingElement =
element => element.AuthenticationScheme =
System.Net.AuthenticationSchemes.IntegratedWindowsAuthentication;
return base.OnConfigureBinding(httpBinding);
}
}
public static class Program()
{
public static void main(string[] args)
{
var config = new NTLMSelfHostConfiguration("https://localhost/");
config.Routes.MapHttpRoute("Main",
"api/{controller}");
var server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
Console.WriteLine("Running");
Console.ReadLine();
server.CloseAsync().Wait();
}
}