边伯贤与鹿晗:SQL Server BI Step by Step SSRS 2----SQL Serv...
来源:百度文库 编辑:九乡新闻网 时间:2024/04/26 03:56:41
SQL SERVER 2008中,Reporting Service不再依赖于IIS,这带来很多利处,不过这也意味着不能够直接通过配置IIS的虚拟目录部署来实现匿名访问了。下面我们就看一下在SSRS 2008中怎么能够实现报表的“匿名访问”,不过对于一个正式项目来说,建议不要并且从不允许匿名来访问报表。(文/孤独侠客)
1. 实现IReportServerCredentials接口
对于使用Asp.Net的ReportViewer控件,实现IReportServerCredentials接口来实现自定义身份验证,然后通过设置成ReportView的属性ServerReport.ReportServerCredentials。此接口的定义:
ImpersonationUser:ReportView在每次WebRequest请求到ReportServer前模拟的一个WindowsIdentity,实际上会调用这个属性的WindowsIdentity.Impersonate方法来完成。如果此属性返回null的话,则默认使用当前线程用户。
NetworkCredentials: 此属性的值将会经由WebRequest.Credentials属性直接传递给WebRequest,如果返回null的话,则默认是CredentialCache.DefaultCredentials,使用当前上下文的系统凭据,这也是通常我们使用的方式。
GetFormsCredentials:这是ReportServer特有的认证体系,如果返回true的话,输出参数将用来调用ReportServer上的LogonUser方法,这个方法是用来支持服务器上的安全扩展插件。
这个接口是如何被使用的呢,我们从report viewer说起。当ASPX page页面执行时,ReportView控件并不是一次性的请求ReportServer。这其间其实需要通过ReportViewer HTTP handler多次请求Report Server.就比如报表中显示一个图片,在客户端生成的html中有图片标签,对于其中的图片会请求ReportView控件,ReportView收到请求后会重新请求ReportServer索要这个图片,ReportServer这时还需要判断当前请求的用户是否和初始的用户一一致,如果一致才会返回图片。其它的例如ReportView提供的打印,导出也是同样的原理。
ReportView控件的IReportServerCredentials的实例的属性,存储在Asp.net SessionState中,这样即保证了安全性,又能够即时的获取到认证信息。不过这个接口提供的灵活性使我们在设置这个凭据时更加灵活,我们可以如下实现:
1. 实现IReportServerCredentials接口
对于使用Asp.Net的ReportViewer控件,实现IReportServerCredentials接口来实现自定义身份验证,然后通过设置成ReportView的属性ServerReport.ReportServerCredentials。此接口的定义:
- public interface IReportServerCredentials
- {
- WindowsIdentity ImpersonationUser { get; }
- ICredentials NetworkCredentials { get; }
- bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority);
- }
ImpersonationUser:ReportView在每次WebRequest请求到ReportServer前模拟的一个WindowsIdentity,实际上会调用这个属性的WindowsIdentity.Impersonate方法来完成。如果此属性返回null的话,则默认使用当前线程用户。
NetworkCredentials: 此属性的值将会经由WebRequest.Credentials属性直接传递给WebRequest,如果返回null的话,则默认是CredentialCache.DefaultCredentials,使用当前上下文的系统凭据,这也是通常我们使用的方式。
GetFormsCredentials:这是ReportServer特有的认证体系,如果返回true的话,输出参数将用来调用ReportServer上的LogonUser方法,这个方法是用来支持服务器上的安全扩展插件。
这个接口是如何被使用的呢,我们从report viewer说起。当ASPX page页面执行时,ReportView控件并不是一次性的请求ReportServer。这其间其实需要通过ReportViewer HTTP handler多次请求Report Server.就比如报表中显示一个图片,在客户端生成的html中有图片标签,对于其中的图片会请求ReportView控件,ReportView收到请求后会重新请求ReportServer索要这个图片,ReportServer这时还需要判断当前请求的用户是否和初始的用户一一致,如果一致才会返回图片。其它的例如ReportView提供的打印,导出也是同样的原理。
ReportView控件的IReportServerCredentials的实例的属性,存储在Asp.net SessionState中,这样即保证了安全性,又能够即时的获取到认证信息。不过这个接口提供的灵活性使我们在设置这个凭据时更加灵活,我们可以如下实现:
- [Serializable]
- class MyConfigFileCredentials : IReportServerCredentials
- {
- public MyConfigFileCredentials()
- {
- }
- public WindowsIdentity ImpersonationUser
- {
- get { return null; }
- }
- public ICredentials NetworkCredentials
- {
- get
- {
- return new NetworkCredential(
- ConfigurationManager.AppSettings["MyUserName"],
- ConfigurationManager.AppSettings["MyPassword"]);
- }
- }
- public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
- {
- authCookie = null;
- userName = null;
- password = null;
- authority = null;
- }
- }
- ReportViewer1.ServerReport.ReportServerCredentials = new MyConfigFileCredentials();
SQL Server BI Step by Step SSRS 2----SQL Serv...
《Microsoft SQL Server 2008 Analysis Services Step by Step》学习笔记二 - 邀月工作室 - 博客园
《Microsoft SQL Server 2008 Analysis Services Step by Step》学习笔记三 - 邀月工作室 - 博客园
Step By Step I
SQL Server Reporting Services(简称SSRS)-sql ser...
Linux Hello World!step by step
step by step 创建oracle数据库
SQL Server笔试题 解答2
SQL SERVER实用
SQL Server日期计算
sql server-平坦软件园
SQL Server死锁总结
SQL Server 优化
SQL SERVER的数据类型
Sql Server实用操作
SQL Server 2000简介
SQL Server 数据库备份
SQL Server DATEDIFF() 函数
Azure Services Platform Step by Step1
SQL
MS Sql Server恢复技术
SQL SERVER事务处理(七)
SQL Server数据库文件恢复技术
SQL Server 2000数据库收缩