返回

ReportViewer中设置ServerReport.ReportServerCredentials属性的方法

发布时间:2023-09-15 03:01:34 243


当使用SSRS技术来布置报表,可能使用MS自带的ReportViewer控件来读取报表.

它分为Web和Windows两种版本;此处Web版.

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

 1) Form认证证书(GetFormsCredentials);

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

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

 

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

 示例代码如下:

ReportViewer1.ShowCredentialPrompts = false;
ReportViewer1.ServerReport.ReportServerCredentials = new ReportSCredentials(userName, userPwd, userAD);
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;


public class ReportSCredentials : IReportServerCredentials
{
private string _UserName;
private string _PassWord;
private string _DomainName;

public ReportSCredentials(string UserName, string PassWord, string DomainName)
{
_UserName = UserName;
_PassWord = PassWord;
_DomainName = DomainName;
}

public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get
{
return null;
}
}

public ICredentials NetworkCredentials
{
get
{
if (string.IsNullOrEmpty(_UserName) || string.IsNullOrEmpty(_PassWord))
{
return null;
}
else if (string.IsNullOrEmpty(_DomainName))
{
return new NetworkCredential(_UserName, _PassWord);
}
else
{
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;
return false;
}

}



特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线