Asp.net报表查看器模拟
我正在ASP.net web应用程序中使用报表查看器控件。应用程序在应用程序池标识(impersonate=“false”)中运行,因此它有权读取/写入数据库 但是对于报表查看器控件,我需要模拟当前登录的用户。到目前为止,我只找到了有关将整个应用程序的模拟设置为true的信息,以便同时模拟报表查看器。或者有关于如何创建自己的凭证并将其传递给查看器的信息(因此它不是当前登录的用户)Asp.net报表查看器模拟,.net,asp.net,reporting-services,.net,Asp.net,Reporting Services,我正在ASP.net web应用程序中使用报表查看器控件。应用程序在应用程序池标识(impersonate=“false”)中运行,因此它有权读取/写入数据库 但是对于报表查看器控件,我需要模拟当前登录的用户。到目前为止,我只找到了有关将整个应用程序的模拟设置为true的信息,以便同时模拟报表查看器。或者有关于如何创建自己的凭证并将其传递给查看器的信息(因此它不是当前登录的用户) 有人知道如何仅为报表查看器模拟当前用户,而不为整个应用程序模拟当前用户吗?如果我理解正确,您需要实现IReportS
有人知道如何仅为报表查看器模拟当前用户,而不为整个应用程序模拟当前用户吗?如果我理解正确,您需要实现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
}
这将允许您传递任何用户名,并通过您喜欢的。这也适用于SSRS 08/SQL 08和id imagine 05,这是使用forms auth
希望这有助于我正确理解你的问题
编辑: 是的,只需从存储当前用户名和密码的位置(会员资格等)检索当前用户名和密码,并按照我的示例传递到
用户名和PASS必须存在于报表服务器本身中,但是,如果您确实需要每个用户的帐户,那么在应用程序本身创建帐户时考虑在报表服务器上创建帐户。您可以通过web服务SSRS公开来实现这一点,请参见此处。如果站点已经在使用中,您可以轻松地遍历所有用户,并通过SSRSWeb服务为他们创建一个帐户
但是,您确定每个用户都需要一个报告帐户吗?如果您的理由是访问权限大于登录权限,则可以为应用程序中的每个角色创建一个帐户。正如我所写,我想模拟当前登录的用户。如何将这些信息传递给自定义凭据“new ReportServerNetworkCredentials(loggedOnUserName?、loggedOnPassword?)”
ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials(username, password);
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://youreportserver/ReportServer");
ReportViewer1.ServerReport.ReportPath = reportPath;
//etc