10

我的应用程序已 Asp.Net MVC3编码C#,我有一个 SSRS 解决方案SQL Server Business Intelligence Developement StudioVisual Studio 2008我正在通过我的Asp.Net MVC3应用程序调用 SSRS 报告。几天前我的应用程序运行良好,但突然出现如下错误:

我的错误:

The request failed with HTTP status 401: Unauthorized.

我的尝试

  1. 我的 SSRS 报告部署在我的local server. 我在我的 SSRS 报告解决方案的数据源中正确设置了我的凭据。

  2. 我试图在我的 web.config 中添加标签<identity impersonate="true" userName="Domain\username" password="Password" />

  3. 我尝试添加IReportServerCredentials reportCredentials = new ReportServerCredentials("MyUserName", "MyPassword", "ServerName");

  4. 我将 Visual Studio 作为'Run as Administrator'.

  5. 我尝试了此链接中提到的解决方案Creating a key using RegEdit

  6. 更新 我也尝试了以下解决方案,但结果相同:SSRS 中的未经授权的错误

上述解决方案都不起作用,但是当我在其他机器上运行相同的解决方案时,解决方案运行良好并且没有显示错误。只有当我从我的机器上运行解决方案时,我才会收到错误The request failed with HTTP status 401: Unauthorized.

4

7 回答 7

3

我有同样的问题。一切正常,然后突然我在reportviewer iframe 中收到401,而不是在调试模式(本地主机)下的报告。我一直在摆弄设置以使其在实时站点上运行,所以我认为我做错了什么...

尝试了几件事,然后决定重新启动并猜猜是什么???我的域密码已过期,因此身份验证失败!!!笨笨笨笨的我!

以为我会在这里添加我的解决方案,以防人们遇到同样的愚蠢情况并浪费宝贵的时间来弄清楚他们做错了什么......

于 2017-01-17T13:54:19.317 回答
3

我也遇到同样的错误,

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();
}

这对我有用!

于 2015-11-04T11:32:31.960 回答
2

Try this

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);
            }


        }
于 2013-10-08T12:39:17.087 回答
1

我遇到的问题是我的 ReportPath。我使用的是在浏览器中呈现的 URL,但应该使用 ReportServer 数据库中的 URL。要获取路径,请查询目录表并使用路径字段中的值。

于 2020-08-27T20:09:15.693 回答
0

请求失败,http 状态 401 未经授权。SSRS 2008

从 web.config 添加 key="RS_UName" value="rajiv-pc" ---- 不正确

用您的系统名称 (rajiv) 替换上面的值,而不是像 rajiv-pc 这样的 sql 服务器名称

总是有系统名称而不是 sql 服务器名称。

从 web.config 添加 key="RS_UName" value="rajiv" --- 正确

于 2013-11-06T08:14:58.053 回答
0

Please just check the web service url you're pointing to. I deployed an SSRS on two separate server and one worked fine while the other threw this error "the request failed with http status 401 unauthorized."

So after a few hours I saw saw that I wasn't pointing to the web service url on my web.config. Example change on the web.config the report service url: http://weburl/ReportServer.

THIS WORKS!!!

于 2019-11-14T12:58:56.217 回答
0

好奇的回答解决了我的问题。谢啦!

另外,检查您的 web.config。它必须具有以下内容:

`

<system.web>
<httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
        validate="false" />
    </httpHandlers>
</system.web>
<system.webServer>
<handlers>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd"
       type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, 
          PublicKeyToken=89845dcd8080cc91" />
</handlers>
  </system.webServer>

`

公共令牌必须相同,否则会引发另一个错误。

于 2015-12-02T02:39:08.243 回答