本文介绍了CSOM - 我可以访问一个服务器场,但无法访问另一个服务器场(远程服务器返回401 - 未经授权)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下方式访问一个网站:
I can access one site just fine using:
string url = "https://filesite.site.com"
ClientContext context = new ClientContext(url);
context.Credentials = new NetworkCredential(@"DomainName\Username", password);
Web website = context.Web;
context.Load(website);
context.ExecuteQuery();
MessageBox.Show(website.Title);
但如果我使用:
string url = "https://filesite2.site.com"
ClientContext context = new ClientContext(url);
context.Credentials = new NetworkCredential(@"DomainName\Username", password);
Web website = context.Web;
context.Load(website);
context.ExecuteQuery();
MessageBox.Show(website.Title);
我收到一条错误,指出"远程服务器返回401 - 未经授权" 。有没有我缺少的设置或什么?
I get an error stating "The remote server returned 401 - Unauthorized". Is there a setting I am missing or something?
推荐答案
请尝试做如下:
1。使用以下代码传递凭据。
1. Use the code below to pass credentials.
context.Credentials = CredentialCache.DefaultNetworkCredentials;
2。检查域名是否正确,并检查用户是否拥有filesite2的权限。
2. Check the domain name is right, and check if the user have permission for the filesite2.
3。在Web应用程序的web.config中添加新设置。
3. Add new settings in web.config of your web application.
<appSettings>
<add key="aspnet:AllowAnonymousImpersonation" value="false" />
</appSettings>
4。检查filesite2站点的备用访问映射。
4. Check the Alternate Access Mappings of the filesite2 site.
最好的问候,
Dennis
这篇关于CSOM - 我可以访问一个服务器场,但无法访问另一个服务器场(远程服务器返回401 - 未经授权)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!