User impersonation between asp.net and ssrs

血红的双手。 提交于 2019-12-19 10:58:27

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/19094828/user-impersonation-between-asp-net-and-ssrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!