C# 请求失败,HTTP 状态为 401:未经授权
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/848397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The request failed with HTTP status 401: Unauthorized
提问by
I have the following error: The request failed with HTTP status 401: Unauthorized. URL:http://serverName/ReportServer/ReportService2005.asmx
我有以下错误:请求失败,HTTP 状态为 401:未经授权。网址:http://serverName/ReportServer/ReportService2005.asmx
I have a web application in one server and reporting service en other.both server have installed Windows 2003. The user in the crediatials is the same the I use to install reporting service and the same the Reportins service service used. Also, this user has the RSS role and is owner in the database and this user is in teh application Pool. is somethig wrong in my code? what is the way to access the reporting service web service using imporsonation?
我在一台服务器上有一个 Web 应用程序,在其他服务器上有一个报告服务。两台服务器都安装了 Windows 2003。凭证中的用户与我用来安装报告服务的用户相同,并且与使用的 Reportins 服务服务相同。此外,此用户具有 RSS 角色并且是数据库中的所有者,并且此用户位于应用程序池中。我的代码有问题吗?使用冒充访问报告服务 Web 服务的方法是什么?
{
ReportingService2005 rs = new ReportingService2005();
try
{
rs.Url = ConfigurationSettings.AppSettings["WSRS"].ToString();
//rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.PreAuthenticate = true;
rs.Credentials = new NetworkCredential(RS.User_Name,RS.Pass_Word,RS.Domain)
);
//string report = "/SampleReports/Employee Sales Summary";
string desc = "Added by workflow automatically";
string eventType = "TimedSubscription";
string scheduleXml = string.Empty;
/*ExtentionSettings Values*/
List<ParameterValue> ExtensionSettingsparmList = new List<ParameterValue>();
foreach (String name in colExtensionSettings.AllKeys)
{
ExtensionSettingsparmList.Add(new ParameterValue() { Name = name, Value = colExtensionSettings[name].ToString() });
}
ExtensionSettings extSettings = new ExtensionSettings();
extSettings.ParameterValues = ExtensionSettingsparmList.ToArray(); // extensionParams;
extSettings.Extension = "Report Server Email";
/*Parameters Values*/
List<ParameterValue> parameterList = new List<ParameterValue>();
foreach (String name in colParameters.AllKeys)
{
parameterList.Add(new ParameterValue() { Name = name, Value = colParameters[name].ToString() });
}
scheduleXml = @"<ScheduleDefinition><StartDateTime>" + DateTime.Now.AddMinutes(1).ToString("s") + "</StartDateTime></ScheduleDefinition>";
string matchData = scheduleXml;
return rs.CreateSubscription(report, extSettings, desc, eventType, matchData, parameterList.ToArray());
}
回答by Dirk Vollmar
This looks like a configuration issue with IIS and NTLM authentication in combination with an AppPool.
这看起来像是 IIS 和 NTLM 身份验证与 AppPool 相结合的配置问题。
This knowledge base article might be a solution:
这篇知识库文章可能是一个解决方案:
当您尝试访问属于 IIS 6.0 应用程序池的网站时,您会收到“HTTP 错误 401.1 - 未经授权:访问因凭据无效而被拒绝”错误消息
回答by SQLChicken
Application pool needs to be running under credentials that have access to website. To ensure security run app pool as a domain user you have created that has access to your database/application with proper security access.
应用程序池需要在有权访问网站的凭据下运行。为确保安全,以您创建的域用户身份运行应用程序池,该域用户可以通过适当的安全访问权限访问您的数据库/应用程序。