3

我有一个发布 RSS 提要的 Intranet,我正在尝试从 Windows 域环境中的同一 IIS 服务器上托管的另一个 Intranet 站点使用该 RSS 提要。

两个网站都有

<authentication mode="Windows">

并且匿名身份验证被禁用。

在本地开发(Windows Auth 但不在域上)以下工作:

var request = HttpWebRequest.Create(feedUrl);
request.Credentials = CredentialCache.DefaultNetworkCredentials;

XElement f;
using (var response = request.GetResponse())
{
     var reader = new XmlTextReader(response.GetResponseStream()); 
     f = XElement.Load(reader);
}
return f;

但是,当我将其部署到生产环境(Windows 2008)时,我得到一个 401 Unauthorized 异常。以域用户身份登录时,我可以在浏览器中毫无问题地查看 RSS 提要,但是当尝试通过代码访问它时,它似乎没有经过身份验证。

我也试过:

request.Credentials = New System.Net.NetworkCredential("myUser","myPass","myDomain");

但仍然是 401 Unauthorized。任何人都可以就我忽略的内容提供想法吗?

4

1 回答 1

0

When you are running locally in VS, CredentialCache.DefaultNetworkCredentials will get your username, whereas when you have this client running on a web server this will return the account used to execute your application under. This is usually a NetworkService account local to your web server. That's why when you attempt to use this client to authenticate against the remote service you are getting 401. So you could configure your ASP.NET MVC client application to execute under a domain account which has permissions to access the remote service. This could be done in the advance properties of the Application Pool in the IIS manager.

于 2013-02-21T21:40:25.120 回答