chi*_*oro 6 asp.net authentication web-services asmx
我遇到了我开发的asmx Web服务的授权错误.Web服务本身不需要任何用户凭据,但似乎Web服务配置为强制执行,尽管我尝试设置配置以允许匿名访问:
我在IIS中设置了相应的网站以允许匿名访问:

此外,我在以下内容中包括以下内容web.config:
<configuration>
...
<system.web>
...
<authorization>
<allow users="*"/>
</authorization>
...
</system.web>
...
</configuration>
Run Code Online (Sandbox Code Playgroud)
当尝试从测试客户端调用Web服务时,我收到以下错误消息:
HTTP请求未经授权,客户端身份验证方案为"匿名".从服务器收到的身份验证标头是"NTLM".
调用Web服务的代码行如下所示:
string message = new ServiceReference1.Service1SoapClient().HelloWorld();
Run Code Online (Sandbox Code Playgroud)
和Web服务的代码:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
Run Code Online (Sandbox Code Playgroud)
一些要点:
我还尝试将授权标记放在指向Web服务的位置标记中:
<location path="Service1.asmx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
Run Code Online (Sandbox Code Playgroud)
这就是客户端配置(app.config)的样子(请注意,如上所述,我甚至无法使用Web浏览器访问该服务,因此我不认为客户端配置相关):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Service1Soap" 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://name.of.the.server.example.org/Service1.asmx"
binding="basicHttpBinding" bindingConfiguration="Service1Soap"
contract="ServiceReference1.Service1Soap" name="Service1Soap" />
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
更新:我找到了以下文件:
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\ASP.NETWebAdminFiles\web.config
Run Code Online (Sandbox Code Playgroud)
它是否与自定义Web应用程序有任何关联,如果是,请不要自己的web.config设置覆盖该文件的设置?
该文件的内容:
<configuration>
<system.web>
<membership>
<providers>
<add name="WebAdminMembershipProvider" type="System.Web.Administration.WebAdminMembershipProvider" />
</providers>
</membership>
<httpModules>
<add name="WebAdminModule" type="System.Web.Administration.WebAdminModule"/>
</httpModules>
<authentication mode="Windows"/>
<authorization>
<deny users="?"/>
</authorization>
<identity impersonate="true"/>
<trust level="Full"/>
<pages validateRequest="true"/>
<globalization uiCulture="auto:en-US" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
虽然还有另一个文件:
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\config\web.config
Run Code Online (Sandbox Code Playgroud)
而且我认为这是系统范围的web.config文件.该文件实际上允许访问所有用户:
<system.web>
<authorization>
<allow users="*"/>
</authorization>
Run Code Online (Sandbox Code Playgroud)
*表示经过身份验证的用户,您需要使用?.
尝试禁用整个网站的身份验证:
<system.web>
<authentication mode="None" />
<authorization>
<allow users="?" />
</authorization>
</system.web>
Run Code Online (Sandbox Code Playgroud)
执行此操作检查:创建test.txt文件并尝试从Web浏览器访问它.你得到'拒绝访问'错误?
接下来,尝试打开不存在的aspx页面,例如blah.aspx.你应该得到404错误,而不是拒绝访问.