User impersonation between asp.net and ssrs

asp.netreporting-servicesssrs-2008

I have a web application that has application pool configured using domain account. In SSRS, domain account is given the browser access to the folder and SSRS report is configured with proper credentials.

My question is if SSRS report is launched from the web application, will SSRS report be opened under domain account or my account. Currently, it is giving error message as \ doesn't have sufficient permissions to access the report location.

Best Answer

You just need to set a fixed user in the web config along with the SSRS address. This way you set a default for the site to use instead of depending on the user running the site:

Example from a WPF app but very similar to ASP.NET in code behind.

<Button x:Name="btnGetViewerRemoteData" Content="Remote" Click="ReportViewerRemote_Load"/>

Reference name of element in code behind, ensure you import Namespace for 'Microsoft.Reporting.WinForms' (or ASP.NET equivalent).

    private void ResetReportViewer(ProcessingMode mode)
    {
        this.reportViewer.Clear();
        this.reportViewer.LocalReport.DataSources.Clear();
        this.reportViewer.ProcessingMode = mode;
    }


    private ICredentials giveuser(string aUser, string aPassword, string aDomain)
    {
        return new NetworkCredential(aUser, aPassword, aDomain);
    }

    private void ReportViewerRemoteWithCred_Load(object sender, EventArgs e)
    {
        ResetReportViewer(ProcessingMode.Remote);
        var user = giveuser("User", "Password", "Domain");
        reportViewer.ServerReport.ReportServerCredentials.ImpersonationUser = (System.Security.Principal.WindowsIdentity)user;
        ;

        reportViewer.ServerReport.ReportServerUrl = new Uri(@"http:// (server)/ReportServer");

        reportViewer.ServerReport.ReportPath = "/Test/ComboTest";

        DataSourceCredentials dsCrendtials = new DataSourceCredentials();
        dsCrendtials.Name = "DataSource1";
        dsCrendtials.UserId = "User";
        dsCrendtials.Password = "Password";
        reportViewer.ServerReport.SetDataSourceCredentials(new DataSourceCredentials[] { dsCrendtials });

        reportViewer.RefreshReport();
    }

I hard coded my example but you can have the server, user and password be in a config file. Although security of password may be a concern so depending on your organization so it may be preferable to hard code it or mask it first.

Related Topic