【问题标题】:.NET Core 3.1 in linux container: The HTTP request is unauthorizedlinux容器中的.NET Core 3.1:HTTP请求未经授权
【发布时间】:2021-03-26 10:04:24
【问题描述】:

我有一些调用 WCF 服务的 .NET Core 3.1 代码:

     var endpoint = new EndpointAddress("https://my-url");
     var client = new MyClient(MyClient.EndpointConfiguration.basicHttpBindingMy, endpoint);

     client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("api username", "api password");
     client.GetStuff();

Visual Studio 自动生成的绑定代码:

    System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
    result.MaxBufferSize = int.MaxValue;
    result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
    result.MaxReceivedMessageSize = int.MaxValue;
    result.AllowCookies = true;
    result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
    result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;

问题

这在 Windows 上完美运行,但在 Linux 容器中运行时(基于 docker 映像 mcr.microsoft.com/dotnet/runtime:3.1),我收到此错误:

System.ServiceModel.Security.MessageSecurityException:HTTP 请求未使用客户端身份验证方案“协商”。 从服务器收到的身份验证标头是“协商, NTLM'。

尝试的解决方案

我尝试了在其他地方找到的以下解决方案,但它们似乎对此没有任何影响:

  1. 在 main() 中调用:AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);

  2. 添加到 Dockerfile:apt-get update && apt-get install -y --no-install-recommends apt-utils gss-ntlmssp

【问题讨论】:

  • 请帮忙分享您的web.configapp.config 文件
  • @Ashok 我没有任何 app.config 文件。这是一个 NET Core 3.1 控制台应用程序。
  • 确认 .NET 5.0 中存在同样的问题
  • 既然你找到了解决方案,你可以取消赏金吗?

标签: linux docker .net-core


【解决方案1】:

我终于找到问题了! 原来是外部因素造成的,在反序列化过程中损坏了部分登录凭据,所以上面的代码甚至不是原因:/

【讨论】:

    【解决方案2】:

    可能会根据操作系统本地支持/启用不同的 SSL 协议。

    尝试强制允许所有可用的安全协议:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    

    【讨论】:

    • 感谢您的建议,但没有任何影响
    猜你喜欢
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-14
    • 2018-07-13
    • 2017-11-21
    相关资源
    最近更新 更多