zoukankan      html  css  js  c++  java
  • ReportViewer中设置ServerReport.ReportServerCredentials属性的方法

     

    当使用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;

            }

     

        }

     

  • 相关阅读:
    【转】BP神经网络
    【转】Matlab的regionprops详解
    【转】本人常用资源整理(ing...)
    【转】LDA-linear discriminant analysis
    [转]推荐几个机器学习算法及应用领域相关的中国大牛:
    【转】机器学习资料推荐
    《转贴》机器学习 机器视觉 图像处理 牛人牛站
    [转]LLE
    UVA10651
    UVA10051
  • 原文地址:https://www.cnblogs.com/lgx5/p/6104601.html
Copyright © 2011-2022 走看看