gpt4 book ai didi

c# - ASP.NET Core 中的 NTLM 授权 WCF 不起作用

转载 作者:行者123 更新时间:2023-11-30 21:44:37 25 4
gpt4 key购买 nike

我遇到了 NTLM 授权问题我的服务可以在 asp.net 上正常工作,但现在我需要在 asp.net core 上使用此服务,但我无法通过授权。

我这样配置绑定(bind):

        var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
binding.OpenTimeout = binding.CloseTimeout =
binding.SendTimeout = binding.ReceiveTimeout = TimeSpan.FromMinutes(1);
binding.MaxReceivedMessageSize = 20971520;
binding.MaxBufferPoolSize = binding.MaxBufferSize = 20971520;
binding.ReaderQuotas.MaxArrayLength =
binding.ReaderQuotas.MaxStringContentLength =
binding.ReaderQuotas.MaxBytesPerRead =
binding.ReaderQuotas.MaxNameTableCharCount = 2097152;

binding.TextEncoding = Encoding.UTF8;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
//binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
binding.TransferMode = TransferMode.Buffered;
binding.AllowCookies = false;

然后添加

        ClientCredentials.Windows.ClientCredential.UserName = service.Login;
ClientCredentials.Windows.ClientCredential.Password = service.Password;

然后我做一些服务请求并得到

---> System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'.

我打开了 fiddler 并比较了两个请求(asp.net 和 core)我发现授权 header 有所不同,但配置文件中的密码和登录名相同。

ASP.NET:

授权:NTLM TlRMTVNTUAABAAAAB4IYogAAAAAAAAAAAAAAAAAAAAAKADk4AAAADw==

核心:

授权:NTLM TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAKADk4AAAADw==

我尝试编写自定义行为,以便在 BeforeSendRequest() 中放置来自 asp.net 的 header 而不是核心变体,但在第二个请求客户端再次发送 header 的核心变体,我再次收到关于 NTLM 的相同消息

可能是我试图在错误的地方发现错误?

最佳答案

我发现了这种行为的原因。在 asp.net 中,我不设置域,只设置登录名和密码就可以了。但是在 asp dotnet core 中它对我不起作用,我添加了域。现在它也适用于 asp dotnet core。

    var credentials = new NetworkCredential
{
UserName = service.Login,
Password = service.Password,
Domain = service.Domain
};
service.ClientCredentials.Windows.ClientCredential = credentials;

关于c# - ASP.NET Core 中的 NTLM 授权 WCF 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40741131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com