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

Sam*_*m M 8 c# sql-server reporting-services ssrs-2008 asp.net-mvc-3

我的应用是在 Asp.Net MVC3编码中C#,我有一个SSRS解决方案SQL Server Business Intelligence Developement StudioVisual Studio 2008,我打电话SSRS通过我的报告Asp.Net MVC3应用.几天前我的应用程序运行正常,但突然我收到如下错误:

我的错误:

The request failed with HTTP status 401: Unauthorized.
Run Code Online (Sandbox Code Playgroud)

我的尝试

  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. 我尝试了此链接中提到的解决方案使用RegEdit创建密钥

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

以上解决方案都没有奏效,但是当我在其他机器上运行相同的解决方案时,解决方案运行良好并且没有显示错误.它只有当我从我的机器运行解决方案然后我得到错误The request failed with HTTP status 401: Unauthorized.

ped*_*ram 5

我也遇到同样的错误,

The request failed with HTTP status 401: Unauthorized.
Run Code Online (Sandbox Code Playgroud)

让我分享一下我尝试过的方法,现在效果很好。

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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

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();
}
Run Code Online (Sandbox Code Playgroud)

这对我有用!


vik*_*kky 2

尝试这个

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


        }
Run Code Online (Sandbox Code Playgroud)