SQL Server Performance

Report Viewer Error :: The request failed with HTTP status 401: Unauthorized

Discussion in 'SQL Server 2005 Reporting Services' started by bubberz, Nov 26, 2008.

  1. bubberz New Member

    I'm trying to call a report viewer from a page prompting for three parameters:
    1. Dropdown list value
    2. Start Date
    3. End Date
    The request failed with HTTP status 401: Unauthorized.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.
    Source Error:
    Line 51:
    Line 52: // Set the report parameters for the report
    Line 53: ReportViewer1.ServerReport.SetParameters(
    ***********************
    ***********************
    The class I'm using is:
    [Serializable()]
    public sealed class MyReportServerCredentials2 : IReportServerCredentials
    {
    #region IReportServerCredentials Members
    private string credUser;
    private string credPassword;
    private string credDomain;
    public MyReportServerCredentials2(string user, string password, string domain)
    {
    credUser = user;
    credPassword = password;
    credDomain = domain;
    }
    public WindowsIdentity ImpersonationUser
    {
    //Use the default windows user. Credentials will be
    //provided by the NetworkCredentials property.
    get { 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 = credUser;
    //Dim userName As String = _
    // ConfigurationManager.AppSettings("MyReportViewerUser")
    if ((string.IsNullOrEmpty(userName)))
    {
    throw new Exception("Missing user name from web.config file");
    }
    //Password
    string password = credPassword;
    //Dim password As String = _
    // ConfigurationManager.AppSettings("MyReportViewerPassword")
    if ((string.IsNullOrEmpty(password)))
    {
    throw new Exception("Missing password from web.config file");
    }
    //Domain
    string domain = credDomain;
    //Dim domain As String = _
    // 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)
    {
    authCookie = null;
    userName = null;
    password = null;
    authority = null;
    //Not using form credentials
    return false;
    }
    #endregion
    }

    ********************
    ********************
    The above class is called in my code behind page_load as:
    if (!Page.IsPostBack)
    {
    // Set the processing mode for the ReportViewer to Remote
    ReportViewer1.ProcessingMode = ProcessingMode.Remote;
    ServerReport serverReport = ReportViewer1.ServerReport;
    ReportViewer1.ServerReport.ReportServerCredentials = new MyReportServerCredentials2("user", "password", "domain");


    // Set the report server URL and report path
    serverReport.ReportServerUrl = new Uri("http://Mydomain/reportserver");
    serverReport.ReportPath = "/correctfolder";

    // Create the sales order number report parameter
    ReportParameter rpDivision = new ReportParameter();
    rpDivision.Name = "Division";
    string rqsDivision = Request.QueryString["Division"];
    rpDivision.Values.Add(rqsDivision);
    // Set the report parameters for the report
    ReportViewer1.ServerReport.SetParameters(
    new ReportParameter[] { rpDivision });
    }
    *******************
    *******************

    In my web.config I have:
    <authentication mode="Windows"/>
    <authorization>
    <allow users="*"/>
    </authorization>
    <identity impersonate="true" userName="registry:HKLMSOFTWARE...ASPNET_SETREG,userName"
    password="registry:HKLMSOFTWARE...ASPNET_SETREG,password" />

    *******************
    *******************
    I've tried several different solutions, and can't get past this 401 error.
  2. satya Moderator

    Unauthorised access relates to the permissions and you should verify your NTFS permissions for the users on the folder C:program FilesMicrosoft SQL ServerMSSQLReporting ServicesReportServer. CHekc for ("Read & Execute", "List Folder Content" and "Read" permissions.
  3. bubberz New Member

    Hi...yes, under the "Security" tab, all my "Group or user names" are able to:
    Read & Execute
    List Folder Content
    Read
    Thanks!

Share This Page