HTTP请求未经授权使用客户端身份验证方案"Negotiate".从服务器收到的身份验证标头是'NTLM'

Vid*_*kas 38 c# windows authentication wcf

几天前,当在客户端和wcf Web服务之间使用Windows身份验证时,我对身份验证问题感到非常头疼.我得到的错误是"HTTP请求未经授权,客户端身份验证方案'协商'.从服务器收到的身份验证头是"NTLM".堆栈上的解决方案都没有工作,因为大多数解决方案与旧方法有关.

Vid*_*kas 25

回答:问题是这个问题的所有帖子都与旧的kerberos和IIS问题相关,其中代理凭据或AllowNTLM属性有帮助.我的情况不同了.我从地面挑选蠕虫数小时后发现的是IIS安装程序列表中的某些IIS安装不包括协商提供程序.所以我不得不添加它并向上移动.我的WCF服务开始按预期进行身份验证.下面是截图,如果您使用匿名身份验证关闭的Windows身份验证,它应该如何.

您需要右键单击Windows身份验证并选择提供程序菜单项.

在此输入图像描述

希望这有助于节省一些时间.

  • 我在哪里可以找到这个选项? (2认同)

小智 6

我已经将我的旧版本的WCF升级到WCF 4并进行了以下更改,希望您也可以进行类似的更改.

1. Web.config:

<system.serviceModel>
      <bindings>
        <basicHttpBinding>
          <binding name="Demo_BasicHttp">
            <security mode="TransportCredentialOnly">
              <transport clientCredentialType="InheritedFromHost"/>
            </security>
          </binding>
        </basicHttpBinding>
      </bindings>
      <services>
        <service name="DemoServices.CalculatorService.ServiceImplementation.CalculatorService" behaviorConfiguration="Demo_ServiceBehavior">
          <endpoint address="" binding="basicHttpBinding"
              bindingConfiguration="Demo_BasicHttp" contract="DemoServices.CalculatorService.ServiceContracts.ICalculatorServiceContract">
            <identity>
              <dns value="localhost"/>
            </identity>
          </endpoint>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
      </services>
      <behaviors>
        <serviceBehaviors>
          <behavior name="Demo_ServiceBehavior">
            <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
            <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
            <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
            <serviceDebug includeExceptionDetailInFaults="false"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <protocolMapping>
        <add scheme="http" binding="basicHttpBinding" bindingConfiguration="Demo_BasicHttp"/>
      </protocolMapping>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

2. App.config:

    <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ICalculatorServiceContract" maxBufferSize="2147483647" maxBufferPoolSize="33554432" maxReceivedMessageSize="2147483647" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="4096" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:24357/CalculatorService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICalculatorServiceContract" contract="ICalculatorServiceContract" name="Demo_BasicHttp" />
    </client>
  </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)


fia*_*iat 5

不是这个确切的问题,但这是谷歌搜索几乎完全相同的错误时的最佳结果:

如果您在调用同一台计算机上托管的 WCF 服务时看到此问题,您可能需要填充BackConnectionHostNames注册表项

  1. 在 regedit 中,找到并单击以下注册表子项:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
  2. 右键单击MSV1_0,指向新建,然后单击Multi-String Value
  3. 在“名称”列中,键入BackConnectionHostNames,然后按 Enter。
  4. 右键单击BackConnectionHostNames,然后单击修改。在“值数据”框中,键入用于计算机上本地共享的 CNAME 或 DNS 别名,然后单击“确定”。
    • 在单独的行中键入每个主机名。

有关详细信息,请参阅在客户端在同一台计算机上调用 IIS 中托管的 WCF 服务引发身份验证错误。


归档时间:

查看次数:

103286 次

最近记录:

6 年,1 月 前