我的 ASP.NET 网站从 App_Code 中的代码调用 .net 服务来检索一些信息。
该网络服务托管于http://mydomain/ws/DirectoryService.asmx
.
每当我在托管所需 .net 服务的同一服务器以外的任何服务器上部署网站时,一切都运行良好。
每当我将站点部署到托管 Web 服务的同一 Web 服务器时,都会收到 401.1 错误。
我在网站的 web.config 中定义了以下绑定:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="LR Directory ServiceSoap" 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="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mydomain/ws/DirectoryService.asmx" binding="basicHttpBinding" bindingConfiguration="LR Directory ServiceSoap" contract="ExpertsServiceReference.LRDirectoryServiceSoap" name="LR Directory ServiceSoap" />
</client>
</system.serviceModel>
显然,问题出在那个绑定上。它无法在同一服务器内工作。如何解决这个问题?
附:如果我注释掉 web.config 中的绑定,网站可以正常加载,但功能不完整,因为它无法连接到服务。
更新:一个非常重要的细节:我的目标网站和 .net 服务都位于同一台服务器、同一 IIS 上,但绑定到不同的外部 IP 地址,因此问题不可能出现在网络访问字段中。
另外,如果我将网站的身份验证模式从“匿名”设置为“Windows”,则一切正常,但每次访问该网站时都需要提供 Windows 凭据。