加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – ASP.NET Web API – NTLM身份验证和HTTPS

发布时间:2020-12-16 09:48:44 所属栏目:asp.Net 来源:网络整理
导读:我有以下配置: 自托管ASP.NET Web API ASP.NET MVC 3 Web应用程序 Web应用程序[2]通过HTTPS与Web API [1]通信. 他们(现在)都住在同一台机器上. Web API [1]的Http绑定配置如下: httpBinding.Security.Mode = HttpBindingSecurityMode.Transport; httpBindi
我有以下配置:

>自托管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();


    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读