请求失败,HTTP状态为401:未经授权的SSRS
我的应用程序在用C#
编码的Asp.Net MVC3
中,我在Visual Studio 2008
中的SQL Server Business Intelligence Developement Studio
中有一个SSRS解决方案,我通过我的Asp.Net MVC3应用程序调用SSRS报告。 几天前我的应用程序运行正常,但突然我收到如下错误:
我的错误:
The request failed with HTTP status 401: Unauthorized.
我的尝试
-
我的SSRS报告部署在我的
local server
。 我在SSRS报告解决方案的数据源中正确设置了我的凭证。 -
我试图在我的web.config中添加标签
-
我尝试添加
IReportServerCredentials reportCredentials = new ReportServerCredentials("MyUserName", "MyPassword", "ServerName");
-
我将Visual Studio作为
'Run as Administrator'
身份'Run as Administrator'
。 -
我尝试了此链接中提到的解决方案使用RegEdit创建密钥
-
更新我尝试了以下解决方案,但结果相同: SSRS中的未经授权的错误
上述解决方案都没有奏效,但是当我在其他机器上运行相同的解决方案时,解决方案运行良好并且没有显示错误。 它只有当我从我的机器运行解决方案然后我得到错误The request failed with HTTP status 401: Unauthorized.
试试这个
public void GetConnectionOfReportServer() { try { NetworkCredential credential = new NetworkCredential("administrator", "password@123", "Domain"); this.reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = credential; //select where the report should be generated with the report viewer control or on the report server using the SSRS service. this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local; this.reportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://localhost/ReportServer"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
我也得到了同样的错误,
The request failed with HTTP status 401: Unauthorized.
让我分享一下我尝试过的东西,现在工作正常。
public class CustomSSRSCredentials : IReportServerCredentials { private string _SSRSUserName; private string _SSRSPassWord; private string _DomainName; public CustomSSRSCredentials(string UserName, string PassWord, string DomainName) { _SSRSUserName = UserName; _SSRSPassWord = PassWord; _DomainName = DomainName; } public System.Security.Principal.WindowsIdentity ImpersonationUser { get { return null; } } public ICredentials NetworkCredentials { get { return new NetworkCredential(_SSRSUserName, _SSRSPassWord, _DomainName); } } public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority) { authCookie = null; user = password = authority = null; return false; } }
在page_load
事件中,
if (!Page.IsPostBack) { ReportViewer1.ProcessingMode = ProcessingMode.Remote; IReportServerCredentials ssrscredentials = new CustomSSRSCredentials("MyUserName", "MyPassword", "ServerName"); ServerReport serverReport = ReportViewer1.ServerReport; ReportViewer1.ServerReport.ReportServerCredentials = ssrscredentials; serverReport.ReportServerUrl = new Uri("ReportPathKey"); serverReport.ReportPath = "/Reports/MyReport"; serverReport.Refresh(); }
这对我有用!
请求失败,http状态401未经授权。 ssrs 2008
来自web.config add key =“RS_UName”value =“rajiv-pc”—-不正确
将上面的值替换为您的系统名称(rajiv)而不是像rajiv-pc这样的sql server名称
总是有系统名称而不是sql server name。
来自web.config add key =“RS_UName”value =“rajiv”—正确
curiousguy的答案解决了我的问题。 谢啦!
另外,请检查您的web.config。 必须具备以下条件:
`
`
公共令牌必须相同,否则会导致另一个错误。
我有同样的问题。 一切正常,然后突然我在reportviewer iframe中收到401而不是我在调试模式下的报告(localhost)。 我一直在摆弄设置让它在现场运行,所以我觉得我做错了什么……
尝试了几件事,然后决定重新启动并猜测是什么??? 我的域密码已过期,因此身份validation失败! 愚蠢的愚蠢我!
以为我会在这里添加我的解决方案以防人们遇到同样的愚蠢情况,并且花费宝贵的时间来弄清楚他们做错了什么……