SSRS 报表 如何匿名查看
昨晚一直研究怎么能匿名访问报表然后给客户看呢?研究了好几种办法我试过的分为三种,其中推荐我认为相对可控一点。1.修改SSRS配置文件来禁止他验证登陆用户权限 操作过的文章: 可以完全匿名访问,因为我们系统是涉及到客户要自己做报表的,所以这里屏蔽了权限问题,那么这种办法对我来说是不可行的。 2.修改IIS配置 操作过的文章: 这种办法和第三种类似但是这个是直接操作IIS的如果集成到系统中也不是很科学。
我用的是通过程序伪装登陆之后获得报表
我觉得这样的好处是,可以控制此账户只有浏览的权限,并不破坏任何东西
需要做的就是两点:
1.前台还是一样,一个ScriptManager 一个ReportViewer
2.而后台代码这样写。其中把登陆用户名和账户都存到存到配置文件当中。请自行添加
3.这个类的介绍:
public partial class One : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ReportParameter para = new ReportParameter("ReportParameter1", "1"); ReportViewer1.ServerReport.ReportServerCredentials = new MyReportServerCredentials(); ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://报表服务器地址/reportserver"); ReportViewer1.ServerReport.ReportPath = "/报表地址"; ReportViewer1.ServerReport.SetParameters(new ReportParameter[] { para }); } } } [Serializable] public sealed class MyReportServerCredentials : IReportServerCredentials { public WindowsIdentity ImpersonationUser { get { // Use the default Windows user. Credentials will be // provided by the NetworkCredentials property. return null; } } public ICredentials NetworkCredentials { get { // Read the user information from the Web.config file. // By reading the information on demand instead of // storing it, the credentials will not be stored in // session, reducing the vulnerable surface area to the // Web.config file, which can be secured with an ACL. // User name string userName = ConfigurationManager.AppSettings ["myReportViewerUser"]; if (string.IsNullOrEmpty(userName)) throw new Exception( "Missing user name from web.config file"); // Password string password = ConfigurationManager.AppSettings ["MyReportViewerPassword"]; if (string.IsNullOrEmpty(password)) throw new Exception( "Missing password from web.config file"); // Domain string domain = ConfigurationManager.AppSettings ["MyReportViewerDomain"]; if (string.IsNullOrEmpty(domain)) throw new Exception( "Missing domain from web.config file"); return new NetworkCredential(userName, password, domain); } } public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority) { authCookie = null; userName = null; password = null; authority = null; // Not using form credentials return false; } }
可以成功访问了。。