SSRS:ASP.NET中引用报表远程认证之ReportServerCredentials属性的设置

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.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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值