SSRS:ASP.NET中引用报表远程认证之ReportServerCredentials属性的设置
来源:互联网 发布:安装禅道pathinfo.php 编辑:程序博客网 时间:2024/06/03 09:25
ReportViewer1.ServerReport.ReportServerCredentials这个属性需要一个接口实例。
ServerReport.ReportServerCredentials属性的类型为Microsoft.Reporting.WebForms.IReportServerCredentials,它可提供三种认证方式所需的证书(Credential):
1) Form认证证书(GetFormsCredentials);
2) 扮演认证证书(ImpersonationUser);
3) 网络认证证书(NetworkCredentials).
当报表的服务器端使用网络认证时,需要实现NetworkCredentials接口,而且必须将GetFormsCredentials()接口的返回值设置为False,否则会导致论证失败.
那么我们如何实现呢,Code如下:
[Serializable] public class CustomReportCredentials : IReportServerCredentials { private string _UserName; private string _PassWord; private string _DomainName; /// <summary> /// 自动从web.config中读取信息 /// </summary> public CustomReportCredentials() { _UserName = ConfigHelper.Get("ReportViewerUser"); _PassWord = ConfigHelper.Get("ReportViewerPassWord"); _DomainName = ConfigHelper.Get("ReportViewerDomain"); } /// <summary> /// 手动指定认证信息 /// </summary> /// <param name="UserName"></param> /// <param name="PassWord"></param> /// <param name="DomainName"></param> public CustomReportCredentials(string UserName, string PassWord, string DomainName) { _UserName = UserName; _PassWord = PassWord; _DomainName = DomainName; }
public System.Security.Principal.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.
//1.若没有指定用户名和密码时,默认为本地认证 if (string.IsNullOrEmpty(_UserName) || string.IsNullOrEmpty(_PassWord)) return null; else if (string.IsNullOrEmpty(_DomainName)) //2.若未指定域,则表示当前请求域 return new NetworkCredential(_UserName, _PassWord); else //3.用户+域认证 return new NetworkCredential(_UserName, _PassWord, _DomainName); } }
public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string user, out string password, out string authority) { authCookie = null; user = password = authority = null;
// Not using form credentials return false; } }
调用方法如下:
ReportViewer1.ProcessingMode = ProcessingMode.Remote; IReportServerCredentials irsc =new CustomReportCredentials("administrator", "xxxxxx", "xxxx"); ReportViewer1.ServerReport.ReportServerCredentials = irsc; ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/"); ReportViewer1.ServerReport.ReportPath = "/test/report1";
参考文章:1.http://www.cnblogs.com/beiguren/archive/2010/01/18/1650709.html2.http://stackoverflow.com/questions/671694/passing-credentials-to-sql-report-server-20083.http://stackoverflow.com/questions/9763282/reportviewer-control-using-reportservercredentials-networkcredentials
转自:http://wguorun.blog.163.com/blog/static/16306238201271663634412/
- SSRS:ASP.NET中引用报表远程认证之ReportServerCredentials属性的设置
- ReportViewer中设置ServerReport.ReportServerCredentials属性的方法
- ssrs 报表固定设置
- ASP.NET之WEB项目中水晶报表的使用
- ASP.NET之WEB项目中水晶报表的使用
- SSRS 如何设置报表参数的日期为当前日期
- 在 ASP.NET 网页中设置控件的 HTML 属性
- 如何控制SSRS报表中数据的访问权限
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- ASP.NET中水晶报表的使用
- 判断一个图是否存在环
- 反编译odex文件
- SSRS:关于“在 Web 窗体上报表查看器 Web 控件需要 System.Web.UI.ScriptManager”
- servlet中配置文件web.xml中的参数context-param和init-param区别
- HDU OJ 4185 Oil Skimming【二分图之黑白染色】
- SSRS:ASP.NET中引用报表远程认证之ReportServerCredentials属性的设置
- 反编译时有些类文件不在代码中
- POJ训练计划2528_Mayor's posters(线段树/成段更新+离散化)
- URAL--1008. Image Encoding
- POJ 2299 Ultra-QuickSort(线段树+离散化)
- 设计模式六大原则(3):依赖倒置原则
- Effective Objective-C(第47-52条)系统架构,foundation、for-in、NSTimer
- hdu4845 状态压缩BFS
- 30天自制操作系统之第13天 定时器(2)