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

C# 请求失败,HTTP状态为401:未经授权,c#,C#,我有以下错误: 请求失败,HTTP状态为401:未经授权。网址: 我在一台服务器上安装了web应用程序,在另一台服务器上安装了报表服务。这两台服务器都安装了Windows 2003。Credials中的用户与我安装reporting service时使用的用户相同,与Reportins service时使用的用户相同。此外,该用户具有RSS角色,是数据库中的所有者,并且该用户位于应用程序池中。我的代码有问题吗?使用Importsonation访问报表服务web服务的方式是什么 {

我有以下错误: 请求失败,HTTP状态为401:未经授权。网址:

我在一台服务器上安装了web应用程序,在另一台服务器上安装了报表服务。这两台服务器都安装了Windows 2003。Credials中的用户与我安装reporting service时使用的用户相同,与Reportins service时使用的用户相同。此外,该用户具有RSS角色,是数据库中的所有者,并且该用户位于应用程序池中。我的代码有问题吗?使用Importsonation访问报表服务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());
            }
{
ReportingService2005 rs=新的ReportingService2005();
尝试
{
rs.Url=ConfigurationSettings.AppSettings[“WSRS”].ToString();
//rs.Credentials=System.Net.CredentialCache.DefaultCredentials;
rs.PreAuthenticate=true;
rs.Credentials=新网络凭据(rs.User\u Name、rs.Pass\u Word、rs.Domain)
);
//string report=“/SampleReports/Employee Sales Summary”;
string desc=“由工作流自动添加”;
string eventType=“TimedSubscription”;
string scheduleXml=string.Empty;
/*扩展设置值*/
List ExtensionSettingsparmList=新列表();
foreach(colExtensionSettings.AllKeys中的字符串名称)
{
ExtensionSettingsparmList.Add(新参数Value(){Name=Name,Value=colExtensionSettings[Name].ToString()});
}
ExtensionSettings extSettings=新的ExtensionSettings();
extSettings.ParameterValues=ExtensionSettingsparmList.ToArray();//extensionParams;
extSettings.Extension=“报表服务器电子邮件”;
/*参数值*/
列表参数List=新列表();
foreach(colParameters.AllKeys中的字符串名称)
{
parameterList.Add(新参数Value(){Name=Name,Value=colParameters[Name].ToString()});
}
scheduleXml=@“+DateTime.Now.AddMinutes(1.ToString(“s”)+”;
字符串matchData=scheduleXml;
返回rs.CreateSubscription(报告、extSettings、desc、eventType、matchData、parameterList.ToArray());
}

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

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


应用程序池需要在有权访问网站的凭据下运行。若要确保安全,请以您创建的具有正确安全访问权限的数据库/应用程序访问权限的域用户身份运行应用程序池