SSRS:ASP.NET中引用报表远程认证之ReportServerCredentials属性的设置
2014-08-10 15:08
531 查看
ReportViewer1.ServerReport.ReportServerCredentials这个属性需要一个接口实例。
ServerReport.ReportServerCredentials属性的类型为Microsoft.Reporting.WebForms.IReportServerCredentials,它可提供三种认证方式所需的证书(Credential):
1) Form认证证书(GetFormsCredentials);
2) 扮演认证证书(ImpersonationUser);
3) 网络认证证书(NetworkCredentials).
当报表的服务器端使用网络认证时,需要实现NetworkCredentials接口,而且必须将GetFormsCredentials()接口的返回值设置为False,否则会导致论证失败.
那么我们如何实现呢,Code如下:
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.html 2.http://stackoverflow.com/questions/671694/passing-credentials-to-sql-report-server-2008 3.http://stackoverflow.com/questions/9763282/reportviewer-control-using-reportservercredentials-networkcredentials 转自:http://wguorun.blog.163.com/blog/static/16306238201271663634412/
相关文章推荐
- SSRS:ASP.NET中引用报表远程认证之ReportServerCredentials属性的设置
- asp.net为前台Runat="server"控件设置样式和添加属性
- ReportViewer中设置ServerReport.ReportServerCredentials属性的方法
- ReportViewer中设置ServerReport.ReportServerCredentials属性的方法
- 关于ASP.NET中独立页面设置身份认证等问题
- 在ASP.NET中访问SQL 2005报表服务的权限设置问题
- 关于ASP.NET中独立页面设置身份认证等问题
- ASP.NET在类中引用Application和Server.MapPath
- ASP.NET 2.0中Gridview利用DataFormatString属性设置数据格式
- 设置asp.net的安全认证密码限制
- asp.net oracle 无法加载 DLL (oci.dll) 无法加载 DLL (oci.dll) 未将对象引用设置到对象的实例,解决方法
- ASP.NET中设置两级菜单联动用户控件的属性为外部使用
- asp.net 动态设置 WebService 引用
- asp.net 关于form认证的一般设置:
- asp.net 关于form认证的一般设置:
- asp.net 动态设置 WebService 引用
- Asp.net ReportViewer 为RDLC报表 传递参数
- asp.net动态设置WebService引用
- asp.net下配置数据源时出现: 未将对象引用设置到对象的实例。
- asp.net 关于form认证的一般设置