调用web services提示Access Denied的解决办法[整理]

王朝other·作者佚名  2007-08-09
窄屏简体版  字體: |||超大  

现象:

asp.net中调用web services时提示错误:

请求因 HTTP 状态 401 失败:Access Denied。

将web services放到另一台服务器问题又不存在该问题。

解决办法:

1.新建方法:

#region GetCredentialCache

/// <summary>

/// 获取CredentialCache

/// 解决访问web service时提示没有权限的问题

/// </summary>

/// <returns></returns>

public static CredentialCache GetCredentialCache()

{

//权限验证web services地址

string WSUrl = RightsServicesUrl;

//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(WSUrl), "Negotiate", new NetworkCredential("域用户名", "域密码", "域"));

return cache;

}

#endregion

2.为web services指定CredentialCache

web services引用名为RightsControl,添加如下代码:

RightsControl rightsControl = new RightsControl();

//为web services指定CredentialCache,最重要的就是这一句

rightsControl.Credentials = GetCredentialCache();

//调用rightsControl的方法

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航