0

----------WebForm--------------------------------------------------------------------------------------------------------------------------------------------------

    [Serializable]
    public class MyReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials
    {
        // local variable for network credential.
        private string _UserName;
        private string _PassWord;
        private string _DomainName;
        public MyReportCredentials(string UserName, string PassWord, string DomainName)
        {
            _UserName = UserName;
            _PassWord = PassWord;
            _DomainName = DomainName;
        }
        public System.Security.Principal.WindowsIdentity ImpersonationUser
        {
            get
            {
                return null; // not use ImpersonationUser
            }
        }
        public System.Net.ICredentials NetworkCredentials
        {
            get
            {
                // use NetworkCredentials
                return new System.Net.NetworkCredential(_UserName, _PassWord, _DomainName);
            }
        }
        public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string user, out string password, out string authority)
        {
            // not use FormsCredentials unless you have implements a custom autentication.
            authCookie = null;
            user = password = authority = null;
            return false;
        }
    }
//--调用
            ReportView.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
            ReportView.ServerReport.ReportServerUrl = new Uri(xxx);
            ReportView.ServerReport.ReportPath =xxx
            //--
            ReportView.ServerReport.ReportServerCredentials = new MyReportCredentials("user", "pwd, "domain");
            //--
            ReportParameter[] rptParams = new ReportParameter[3];
            rptParams[0] = new ReportParameter("xx", xx);
            rptParams[1] = new ReportParameter("xx", xx);
            rptParams[2] = new ReportParameter("xx", xx);
            ReportView.ServerReport.SetParameters(rptParams);
******在设置ReportServerCredentials前,要对 ReportViewer1.ServerReport.ReportServerUrl和ReportViewer1.ServerReport.ReportPath赋值;
----------WinForm--------------------------------------------------------------------------------------------------------------------------------------------------
      使用.Net 开发Windows应用程序,使用ReportView控件可以访问报表服务器上的报表,System.Net.NetWorkCredentials 在Visual Studio 2008中可以隐式转换为ReportServerCredentials
        下面是一个WinForm访问报表服务的范例:
         ReportUser 是一个有报表服务访问权限的Windows用户
         System.Net.NetworkCredential("ReportUser", "password", "")中的三个参数分别是:报表服务访问账号、密码和域名;如果是本地账号,域名可以为空。
 
            this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
            this.reportViewer1.ServerReport.ReportServerUrl = new System.Uri("http://xxx/reportserver");
            this.reportViewer1.ServerReport.ReportPath = "/xxx/;
            this.reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials
                    = new System.Net.NetworkCredential("ReportUser", "password", "");
            this.reportViewer1.RefreshReport();


关闭 返回顶部
联系我们
Copyright © 2011. 聚财吧. All rights reserved.