请求失败,HTTP状态为401:未授权

时间:2009-05-11 14:31:29

标签: c#

我有以下错误: 请求失败,HTTP状态为401:未授权。网址:http://serverName/ReportServer/ReportService2005.asmx

我在一台服务器上有一个Web应用程序,在另一台服务器上有报告服务。两台服务器都安装了Windows 2003.信誉中的用户与我用来安装报告服务和使用的Reportins服务相同。此外,此用户具有RSS角色并且是数据库中的所有者,并且此用户位于应用程序池中。在我的代码中有些不对劲?使用imporsonation访问报告服务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());
            }

2 个答案:

答案 0 :(得分:2)

这看起来像是IIS和NTLM身份验证与AppPool结合使用时的配置问题。

这篇知识库文章可能是一个解决方案:

  

You receive an "HTTP Error 401.1 - Unauthorized: Access is denied due to invalid credentials" error message when you try to access a Web site that is part of an IIS 6.0 application pool

答案 1 :(得分:1)

应用程序池需要在有权访问网站的凭据下运行。安全性运行应用程序池作为您创建的域用户,可以访问具有适当安全访问权限的数据库/应用程序。

相关问题