2
votes

I'm using ReportViewer for connecting to report server. Windows authenticaton works well.. but when I used credentials to authenticate to report server I got the error:

The request failed with HTTP status 401: Unauthorized.

I know I need to configure the report server to accept those credentials, but I don't know actually what it is. Yes I have gone through msdn as well as stack questions too. I'm a complete beginner to SSRS and I want to integrate report server into my web application. what I have done in my application page is:

protected void Page_Load(object sender, EventArgs e)
{
    //    if (!IsPostBack)
    //    {
            ReportViewer1.ServerReport.ReportServerCredentials =
             new MyReportServerCredentials();
        //    ReportViewer1.ServerReport.Refresh();
        //}
    }
}

[Serializable]
public sealed class MyReportServerCredentials : IReportServerCredentials
{
    public WindowsIdentity ImpersonationUser
    {
        get
        {
            // Use the default Windows user.  Credentials will be
            // provided by the NetworkCredentials property.
            return null;
        }
    }

    public ICredentials NetworkCredentials
    {
        get
        {
            // Read the user information from the Web.config file.  
            // By reading the information on demand instead of 
            // storing it, the credentials will not be stored in 
            // session, reducing the vulnerable surface area to the
            // Web.config file, which can be secured with an ACL.

            // User name
            string userName =
                ConfigurationManager.AppSettings
                    ["MyReportViewerUser"];

            if (string.IsNullOrEmpty(userName))
                throw new Exception(
                    "Missing user name from web.config file");

            // Password
            string password =
                ConfigurationManager.AppSettings
                    ["MyReportViewerPassword"];

            if (string.IsNullOrEmpty(password))
                throw new Exception(
                    "Missing password from web.config file");

            // Domain
            string domain =
                ConfigurationManager.AppSettings
                    ["MyReportViewerDomain"];

            if (string.IsNullOrEmpty(domain))
                throw new Exception(
                    "Missing domain from web.config file");

            return new NetworkCredential(userName, password, domain);
        }
    }

    public bool GetFormsCredentials(out Cookie authCookie,
                out string userName, out string password,
                out string authority)
    {
        // not use FormsCredentials unless you have implements a custom autentication.
        authCookie = null;
        userName = null;
        password = null;
        authority = null;

        // Not using form credentials
        return false;
    }
}

And in the RsReportServer.config file I modified and replaced the <authentication> node with:

<Authentication>
      <AuthenticationTypes>
             <Custom />
      </AuthenticationTypes>
      <EnableAuthPersistence>true</EnableAuthPersistence>
</Authentication>

And in web.config file of reportserver I changed authentication to forms and impersonate to false, and I did the same in web.config file of reportmanager .

Anything missing. or am I right?

I also guess I need to do something with CustomSecurity Extension term?

2
At a first glance it seems your code's okay. The best suggestion I have (that should help you find out more, and help us understand the question better) is to trim down the code even more. Take out the commented lines, replace the AppSettings with hardcoded strings, etc: make the example as small as possible.Jeroen
now the form authentication in my local computer works well.. (i m using the active directory uname and pwd as credentials.. the error was because the credentials i passed was not correct).. Now when i tried to view reports from application of another computer(two computers are in network)i.e; report server is in my computer .. I got the same error..neeranzan

2 Answers

0
votes

Searching on

http://blogs.msdn.com/b/bimusings/archive/2005/12/05/500195.aspx

Though this is old - this should be a good reference for a check list of things to make it work.

0
votes

You have to configure your SSRS service (located on server), with the help of Start -> All Programs -> Microsoft SQL server 2008 -> Configuration Tool -> Reporting Services Configuration Manager (SSRS)

http://msdn.microsoft.com/en-us/library/ms156305.aspx