博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SSRS:ASP.NET中引用报表远程认证之ReportServerCredentials属性的设置
阅读量:4920 次
发布时间:2019-06-11

本文共 3358 字,大约阅读时间需要 11 分钟。

  ReportViewer1.ServerReport.ReportServerCredentials这个属性需要一个接口实例。

ServerReport.ReportServerCredentials属性的类型为Microsoft.Reporting.WebForms.IReportServerCredentials,它可提供三种认证方式所需的证书(Credential):

 1) Form认证证书(GetFormsCredentials);

 2) 扮演认证证书(ImpersonationUser);

 3) 网络认证证书(NetworkCredentials). 

 当报表的服务器端使用网络认证时,需要实现NetworkCredentials接口,而且必须将GetFormsCredentials()接口的返回值设置为False,否则会导致论证失败.

  那么我们如何实现呢,Code如下:

View Code
[Serializable]    public class CustomReportCredentials : IReportServerCredentials    {        private string _UserName;        private string _PassWord;        private string _DomainName;        ///         /// 自动从web.config中读取信息        ///         public CustomReportCredentials()        {            _UserName = ConfigHelper.Get("ReportViewerUser");            _PassWord = ConfigHelper.Get("ReportViewerPassWord");            _DomainName = ConfigHelper.Get("ReportViewerDomain");        }        ///         /// 手动指定认证信息        ///         ///         ///         ///         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 =newCustomReportCredentials("administrator","xxxxxx","xxxx"); ReportViewer1.ServerReport.ReportServerCredentials= irsc; ReportViewer1.ServerReport.ReportServerUrl=newUri("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

 

转载于:https://www.cnblogs.com/greatwang/archive/2012/08/16/2648223.html

你可能感兴趣的文章
米洛个人修炼术:情绪的四种常用处理方式,其实都是有问题的
查看>>
[翻译] Virtual method interception 虚方法拦截
查看>>
--- git-svn 使用环境和步骤
查看>>
flutter AS 打包
查看>>
Python webpy微信公众号开发之 回复图文消息
查看>>
ubuntu多版本cuda并存与切换【两个博客链接】
查看>>
html5新特性之DOCTYPE声明
查看>>
POJ 3299 Humidex 难度:0
查看>>
快速切题 poj3414 Pots
查看>>
Linux 常用命令
查看>>
五家共井(第1届第3题)
查看>>
c文件操作
查看>>
《Spring In Action》 读书笔记(2) -- bean装配 ...
查看>>
很好很強大..
查看>>
Oracle之子查询:Top-N问题
查看>>
PAT:1011. A+B和C (15) AC
查看>>
JS中的内置对象
查看>>
Android--在Android应用中愉快地写C/C++代码(转)
查看>>
IOSUIcontrol事件
查看>>
docker 部署spring.boot项目【一】(引用外部配置文件)
查看>>