xr2*_*0xr 8 asp.net authentication iis wcf web-services
好的,我已经阅读了我可以通过此错误找到的每个主题和问题,并且令人惊讶地没有找到解决方案.我正在尝试在我的IIS托管的WCF服务(.NET 4.0)上要求Windows身份验证,直到现在,该服务都是可选的.我已经在服务器上提供了一个启用Windows身份验证的端点,但有几个远程应用程序成功使用它.我现在正尝试将使用WCF服务的Web应用程序和其他服务器应用程序切换到此安全端点,方法是为它们提供与工作远程客户端完全相同的客户端配置,但服务器应用程序正在接收带有以下消息的401:
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.]
我为WCF托管站点启用了匿名和Windows身份验证.我开始使用的Web应用程序托管在与WCF服务不同的服务器上,并且运行在ASP.NET 2.0和Windows Server 2008 R2 Enterprise上.我已经使用allowNtlm创建了客户端行为,并将NetworkSecurity:LAN Manager身份验证级别设置为在客户端发送LM和NTLM .... 在托管端,它被设置为发送NTLMv2仅响应...我不知道这是否会影响服务器/服务处理身份验证的方式.我也尝试在客户端上设置allowedImpersonationLevel为Impersonation,谢天谢地,它不起作用(因为模拟不应该是必要的).对于在与Web应用程序相同的服务器上运行的Windows服务和控制台应用程序,我们似乎得到了相同的结果.
这是我的服务器配置:
<binding name="WindowsSecuredBinding">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
...
<service behaviorConfiguration="OMWebServices.QueueServiceBehavior"
name="OMWebServices.QueueService">
<endpoint address="" binding="basicHttpBinding" name="QueueEndpoint"
bindingName="" contract="OMWebServices.IQueueService" />
<endpoint binding="basicHttpBinding" bindingConfiguration="WindowsSecuredBinding"
name="QueueSecuredEndpoint" contract="OMWebServices.IQueueService" />
<endpoint address="mex" binding="mexHttpBinding" name="QueueMetadataEndpoint"
contract="IMetadataExchange" />
</service>
...
<behavior name="OMWebServices.QueueServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
Run Code Online (Sandbox Code Playgroud)
这是客户端配置:
<endpoint address="https://.../QueueService.svc" binding="basicHttpBinding" bindingConfiguration="QueueSecuredEndpoint" behaviorConfiguration="OMServiceBehavior" contract="OMQueueService.IQueueService" name="QueueSecuredEndpoint" />
<binding name="QueueSecuredEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
....
<!-- The behavior I tried that didn't make a difference -->
<behavior name="OMServiceBehavior">
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation" allowNtlm="True"/>
</clientCredentials>
</behavior>
Run Code Online (Sandbox Code Playgroud)
我的第一个问题是,这个错误信息告诉我的是什么?它说客户端方案是Negotiate,服务器响应Negotiate,NTLM.如果服务器提供Negotiate并且客户端正在使用Negotiate,那么问题是什么?
第二个问题显然是错误的,我该如何使其发挥作用?
编辑
嗯,这是愚蠢的.问题似乎是没有传递凭据.当网站开发时,我开始编写代码以在代码中明确设置凭据,但在此过程中,发现它已经在没有明确设置它们的情况下工作.所以代码仍然被注释掉了.这是在IIS 6上运行.现在在IIS 7上运行,它似乎只有在我的代码中明确设置凭据才有效.我可以使用w3wp进程帐户自动获取吗?
要回答第一个问题,错误信息正在告诉我它的确切含义; 我没有被授权.告诉我客户端身份验证方案和服务器头的行只是额外信息,而不是冲突的指示.实际上确认配置是正确的.
在暂存环境中,问题被屏蔽,因为WCF服务和Web应用程序托管在同一服务器上.问题是Web应用程序的站点被配置为默认情况下为匿名用户使用IUSR(或IUSR_Server),一个本地帐户.这是传递的用户(我相信它等于CredentialCache.DefaultNetworkCredentials).当它们位于不同的服务器上时,服务器2上的WCF显然无法验证服务器1用户.解决方案在IIS中,右键单击匿名身份验证>编辑...>检查应用程序池标识(在我的情况下是域帐户)或输入特定用户的域帐户.