Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

c# - The request failed with HTTP status 401: Unauthorized IN SSRS

My Application is in Asp.Net MVC3 coded in C#, i have a SSRS solution in SQL Server Business Intelligence Developement Studio in Visual Studio 2008 , I'm calling the SSRS report through my Asp.Net MVC3 application. My application was running fine a couple of days back but suddenly i'm getting an error as follows:

My Error :

The request failed with HTTP status 401: Unauthorized.

My Attempts

  1. My SSRS reports are deployed on my local server. I have my credential properly set in the datasource of my SSRS report solution.

  2. I tried to add the tag in my web.config <identity impersonate="true" userName="Domainusername" password="Password" />

  3. I tried adding IReportServerCredentials reportCredentials = new ReportServerCredentials("MyUserName", "MyPassword", "ServerName");

  4. I ran the Visual Studio as 'Run as Administrator'.

  5. I tried the solution mentioned in this link Creating a key using RegEdit

  6. Update I tried the following solution as well but the same result : Unauthorized error in SSRS

None of the above solutions worked, but when i run the same solution on some other machine than the solutions works well and no error is displayed. Its only when i run the solution from my machine then i get the error The request failed with HTTP status 401: Unauthorized.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am also getting the same error,

The request failed with HTTP status 401: Unauthorized.

Let me share what I tried and it is working fine now.

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

Inside page_load event,

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

This worked for me!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...