ASP.NET Postgraduate Report Submission

I am using the report viewer in an ASP.net web application. The application runs in the application pool identifier (impersonate = "false"), so it has read / write permissions to the database.

But for the report viewing control, I need to impersonate the current user. So far, I have found information about setting the impersonation to true for the entire application, so the report viewer also stands out for him. Or there is information on how to create your own credentials that are passed to the viewer (therefore, it is not currently a registered user).

Does anyone know how to impersonate the current user only for the report viewer, but not for the entire application?

+3
source share
1 answer

If you correctly understood that you need to implement IReportServerCredentials, here is an example that was used in the past

using System;
using System.Configuration;
using System.Web;
using Microsoft.Reporting.WebForms;
using System.Security.Principal;
using System.Net;

[Serializable]
public sealed class ReportServerNetworkCredentials : IReportServerCredentials
{
#region IReportServerCredentials Members

private string username, password;

public ReportServerNetworkCredentials(string username, string password)
{
    this.username = username;
    this.password = password;
}

public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string userName, out string password, out string authority)
{
    //throw new NotImplementedException(); 
    userName = password = authority = null;

    // The cookie name is specified in the <forms> element in Web.config (.ASPXAUTH by default)
    HttpCookie cookie = HttpContext.Current.Request.Cookies[".ASPXAUTH"];

    if (cookie == null)
    {
        authCookie = null;
        return false;
    }

    Cookie netCookie = new Cookie(cookie.Name, cookie.Value);
    if (cookie.Domain == null)
    {
        netCookie.Domain = HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToUpper();
    }

    netCookie.Expires = cookie.Expires;
    netCookie.Path = cookie.Path;
    netCookie.Secure = cookie.Secure;
    authCookie = netCookie;
    return true;
}

public WindowsIdentity ImpersonationUser
{
    get
    {
        return null;
    }
}

public System.Net.ICredentials NetworkCredentials
{
    get
    {
        return new System.Net.NetworkCredential(this.username, this.password);
    }
}

#endregion
}

And then on the aspx page with the report viewer, submit your credentials, etc.

    ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials(username, password);
    ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://youreportserver/ReportServer");
    ReportViewer1.ServerReport.ReportPath = reportPath;
    //etc

This will allow you to transfer any username and transfer to you. This works on SSRS 08 / SQL 08, and id anticipate 05 too, it uses auth forms.

Hope this helps, and I understood your question correctly.


Edit: Yes, just download the current username and password from where you store them (membership, etc.), and go to my example.

, , , . -, SSRS, . . , - SSRS.

, , ? , , .

+3

Source: https://habr.com/ru/post/1741061/


All Articles