the*_*man 4 c# web-services credentials asmx
我在本地运行一个Web服务,连接到我无法访问的外部服务器.
即使此Web服务的管理员确认测试凭据完全正确,我仍然收到"401:Unauthorized"错误.
我需要调整任何IIS设置吗?
这是错误的屏幕截图.

// Webservice
IdentityService ws = new IdentityService();
// Test Static Credentials
string username = "twfnf";
string password = "testme99";
string domain = "testapps1";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
CredentialCache credCache = new CredentialCache();
credCache.Add(new Uri(ws.Url), "Basic", credentials);
ws.Credentials = credCache;
ws.PreAuthenticate = true;
ws.AuthenticateUser();
Run Code Online (Sandbox Code Playgroud)
使用基本身份验证删除以下代码,修复了该问题.
CredentialCache credCache = new CredentialCache();
credCache.Add(new Uri(ws.Url), "Basic", credentials);
Run Code Online (Sandbox Code Playgroud)
最终守则工作:
// Webservice
IdentityService ws = new IdentityService();
// Test Static Credentials
string username = "twfnf";
string password = "testme99";
string domain = "testapps1";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
ws.Credentials = credentials;
ws.PreAuthenticate = true;
ws.AuthenticateUser();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20099 次 |
| 最近记录: |