说的比较罗嗦,但是我尽量说清楚。。。哪位大侠知道,请明示,不胜感激
我的报表是使用vs2010做好的rdl格式的报表,并且已经部署到reportserver,在本机的//localhost/reportserver中可以访问。
然后我再web页面中使用一个reportviewer控件来显示该报表
如果只设置报表服务器和报表路径的话(如下语句),报表可以正常在页面上显示
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://localhost/reportserver");
ReportViewer1.ServerReport.ReportPath = "/report/report1";
/**************到这里为止报表显示都是正常的**************************/
问题来了
但是由于我想控制报表权限,所以使用了一个自定义的CustomReportCredentials类,这个类的作用就是模拟报表服务器上的用户,这样我就可以使用报表服务器上的用户权限管理来控制我的报表访问权限
语句如下:
ReportViewer1.ServerReport.ReportServerCredentials = new CustomReportCredentials("reporter", "123456", "");
reporter这个用户的权限可以访问我报表服务器上report目录下所有报表,这个在//localhost/reportserver中测试也正常
但是加了这个语句后,我页面上的报表无法加载数据,可以显示输入查询参数的输入框,但是点击查看报表以后,就是没有数据
/**************以下是我CustomReportCredentials类的全文**************************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WebForms;
/// <summary>
/// Summary description for CustomReportCredentials
/// </summary>
[Serializable]
public class CustomReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials
{
// local variable for network credential.
private string _UserName;
private string _PassWord;
private string _DomainName;
public CustomReportCredentials(string UserName, string PassWord, string DomainName)
{
_UserName = UserName;
_PassWord = PassWord;
_DomainName = DomainName;
}
public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get
{
return null; // not use ImpersonationUser
}
}
public System.Net.ICredentials NetworkCredentials
{
get
{
// use NetworkCredentials
return new System.Net.NetworkCredential(_UserName, _PassWord, _DomainName);
}
}
public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string user, out string password, out string authority)
{
// not use FormsCredentials unless you have implements a custom autentication.
authCookie = null;
user = password = authority = null;
return false;
}
}