.net - Asp.net 报表查看器模拟

标签 .net asp.net reporting-services

我在 ASP.net Web 应用程序中使用报表查看器控件。该应用程序以应用程序池标识 (impersonate="false") 运行,因此它有权读/写数据库。

但对于报表查看器控件,我需要模拟当前登录的用户。到目前为止,我只找到了有关将整个应用程序的模拟设置为 true 的信息,以便也模拟报表查看器。或者有关于如何创建自己的凭证并传递给查看者的信息(因此它不是当前登录的用户)。

有谁知道如何仅为报表查看器而不是整个应用程序模拟当前用户?

最佳答案

如果我理解正确,您需要实现 IReportServerCredentials,这是我过去使用的示例

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
}

然后在带有报告查看器的 aspx 页面上输入您的凭据等

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

这将允许您传递任何用户名并传递您喜欢的。这适用于 SSRS 08/SQL 08 和 id imagine 05,这是使用表单验证。

希望这对您有所帮助,并且我能正确理解您的问题。


编辑: 是的,只需从您将它们存储(成员(member)资格等)的位置检索当前用户名和密码,然后按照我的示例将其传递给。

用户名和密码必须存在于报表服务器本身中,但是,如果您确实需要为每个用户创建帐户,请考虑在应用程序本身中创建帐户时在报表服务器上为他们创建一个帐户。您可以通过 SSRS 公开的 Web 服务执行此操作,请参见此处。如果该站点已在使用中,您可以轻松地遍历所有用户并通过 SSRS 网络服务为他们创建一个帐户。

但是,您确定每个用户都需要一个报告帐户吗?如果您的原因是更多的访问权限而不是日志记录,您可以为应用程序中的每个角色创建一个帐户。

关于.net - Asp.net 报表查看器模拟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2636389/

相关文章:

jquery - 如何以多列表格格式显示自动完成列表?

reporting-services - SSRS - OutOf MemoryException - 可以显示的行数是否有限制

reporting-services - 如何从SSRS中的字符串获取特定值

.net - 使用 PropertyChanged.Fody 构建应用程序时出错

c# - 通过 XSLT 在 XML 中格式化日期

c# - 在来自asp.net的上传文件中以C#编辑mp3

asp.net - angular 4部署到asp.net网站给出错误

c# - 单击链接按钮时显示面板

.net - 合并 .net 对象图

sql-server - 我可以用 Azure Scheduler 替换 SQL 作业吗?