The request failed with HTTP status 401:Access Denied
2007-05-17 11:09
573 查看
症状
loadTOCNode(1, 'symptoms');当您尝试调用 Web 服务应用程序并且匿名访问身份验证处于关闭状态时,可能会收到以下错误信息。
The request failed with HTTP status 401:Access Denied.
Description:An unhandled exception occurred during the execution of the current Web request.Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.Net.WebException:The request failed with HTTP status 401:Access Denied.
回到顶端
原因
loadTOCNode(1, 'cause');当匿名访问身份验证对 Web 服务应用程序关闭时,所有的调用方应用程序在发出任何请求之前必须提供凭据。默认情况下,Web 服务客户端代理不继承运行 Web 服务客户端应用程序的安全上下文的凭据。
回到顶端
解决方案
loadTOCNode(1, 'resolution');要解决这个问题,必须使用 Web 服务客户端代理的凭据属性为 Web 服务客户端身份验证设置安全凭据。
要设置凭据属性,请执行下列操作之一:
• | 第一种方法 将 DefaultCredentials 分配给 Web 服务代理类的凭据属性,以在匿名访问身份验证关闭时调用 Web 服务。CredentialCache 类的 DefaultCredentials 属性提供运行应用程序的安全上下文的系统凭据。为此,请使用以下代码: Visual C# .NET 示例 [code] //Assigning DefaultCredentials to the Credentials property //of the Web service client proxy (myProxy). myProxy.Credentials= System.Net.CredentialCache.DefaultCredentials; [/code]Visual Basic .NET 示例 [code] 'Assigning DefaultCredentials to the Credentials property 'of the Web service client proxy (myProxy). myProxy.Credentials= System.Net.CredentialCache.DefaultCredentials [/code] |
• | 第二种方法 您还可以使用 CredentialCache 类为 Web 服务客户端身份验证提供凭据。创建 CredentialCache 类的实例。创建使用指定的用户名、密码和域的 NetworkCredential 的实例。将 NetworkCredential 添加到具有身份验证类型的 CredentialCache 类。为此,请使用以下代码: Visual C# .NET 示例 [code] //Create an instance of the CredentialCache class. CredentialCache cache = new CredentialCache(); // Add a NetworkCredential instance to CredentialCache. // Negotiate for NTLM or Kerberos authentication. cache.Add( new Uri(myProxy.Url), "Negotiate", new NetworkCredential("UserName", "Password", "Domain")); //Assign CredentialCache to the Web service Client Proxy(myProxy) Credetials property. myProxy.Credentials = cache; [/code] Visual Basic .NET 示例 [code]'Create an instance of the CredentialCache class. Dim cache As CredentialCache = New CredentialCache() 'Add a NetworkCredential instance to CredentialCache. 'Negotiate for NTLM or Kerberos authentication. cache.Add(New Uri(myProxy.Url), "Negotiate", New NetworkCredential("UserName", "Password", "Domain")) 'Assign CredentialCache to the Web service Client Proxy(myProxy) Credetials property. myProxy.Credentials = cache [/code] |
有关如何设置凭据属性的更多信息,请参阅本文中的“更多信息”部分。
回到顶端
状态
loadTOCNode(1, 'status');这种现象是由设计导致的。
回到顶端
更多信息
loadTOCNode(1, 'moreinformation');DefaultCredentials 代表运行应用程序的当前安全上下文的系统凭据。对于客户端的应用程序,默认凭据通常是 Windows 凭据,例如运行该程序的用户的用户名、密码和域。对于 ASP.NET 程序,默认凭据是 ASP.NET 辅助进程的标识(或者正在模拟的用户)的用户凭据。在以下示例 ASP.NET 程序中,DefaultCredentials 代表 ASPNET 用户帐户(对于在 Microsoft Internet 信息服务 [IIS] 6.0 上运行的应用程序,则是 NetworkService 用户帐户),因为没有对调用方设置模拟。
回到顶端
重现此问题的步骤
loadTOCNode(2, 'moreinformation');1. | 使用 Visual C# .NET 或 Visual Basic .NET 创建新的“ASP.NET Web 服务”。 | ||||||||||||||||||||
2. | 将该项目命名为“WebServiceTest”。 | ||||||||||||||||||||
3. | 默认情况下,会创建“Service1.asmx”。 | ||||||||||||||||||||
4. | 取消默认 WebMethod“HelloWorld()”的备注标记。 | ||||||||||||||||||||
5. | 在“生成”菜单上,单击“生成解决方案”。 | ||||||||||||||||||||
6. | 关闭对 WebServiceTest 的匿名访问。为此,请按照下列步骤操作:
| ||||||||||||||||||||
7. | 在“生成”菜单上,单击“生成解决方案”。 | ||||||||||||||||||||
8. | 在浏览器中键入下面的地址以查看“Service1”Web 服务说明: http://localhost/WebServiceTest/Service1.asmx | ||||||||||||||||||||
9. | 测试 HelloWorld WebMethod。WebMethod 能够如期工作。 | ||||||||||||||||||||
10. | 将一个 Web 引用添加到测试“ASP.NET Web 应用程序”。为此,请按照下列步骤操作:
| ||||||||||||||||||||
11. | 在解决方案资源管理器中,右键单击“WebForm1.aspx”,然后单击“查看代码”。 | ||||||||||||||||||||
12. | 将以下代码附加到 Page_Load 事件: Visual C# .NET 示例: [code] // Start an instance of the Web service client-side proxy. localhost.Service1 myProxy = new localhost.Service1(); Response.Write( myProxy.HelloWorld()); [/code]Visual Basic .NET 示例: [code]'Start an instance of the Web service client-side proxy. Dim myProxy As localhost.Service1 = New localhost.Service1() Response.Write(myProxy.HelloWorld()) [/code] | ||||||||||||||||||||
13. | 在“调试”菜单上,单击“开始”,然后在浏览器中查看应用程序。 | ||||||||||||||||||||
14. | “症状”部分讨论的错误信息将会出现在浏览器中。 | ||||||||||||||||||||
15. | 要解决此问题,请将 DefaultCredentials 分配给 Web 服务客户端代理的 Credentials 属性。为此,请在行“Response.Write( myProxy.HelloWorld())”之前插入以下代码: Visual C# .NET 示例: [code] myProxy.Credentials= System.Net.CredentialCache.DefaultCredentials; [/code]Visual Basic .NET 示例: [code] myProxy.Credentials = System.Net.CredentialCache.DefaultCredentials [/code] | ||||||||||||||||||||
16. | 重复第 13 步。 |
相关文章推荐
- The request failed with HTTP status 401: Access Denied
- The request failed with HTTP status 401:Access Denied
- The request failed with HTTP status 401:Access Denied
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
- 访问File System的Web Service出现The request failed with HTTP status 401: Unauthorized错误
- the request failed with http status 401:unauthorized
- The request failed with HTTP status 401: Unauthorized
- Web Service出现The request failed with HTTP status 401: Unauthorized错误
- 访问WebService出现IIS错误:The request failed with HTTP status 401: Unauthorized
- The request failed with HTTP status 401: Unauthorized. SSRS 2008
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”-ZT
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
- The request failed with HTTP status 401: Unauthorized
- The request failed with HTTP status 417: Expectation failed.
- Failed to load resource: the server responded with a status of 400 (Bad Request)
- Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
- Failed to load resource: the server responded with a status of 400 (Bad Request)
- 关于使用springmvc时Failed to load resource: the server responded with a status of 400 (Bad Request)错误可能原因
- Failed to load resource: the server responded with a status of 400 (Bad Request)
- Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)