日期:2014-05-18  浏览次数:20760 次

reportview调用服务器报表的时候身份认证问题
C# code
public class CustomReportCredentials : Microsoft.Reporting.WinForms.IReportServerCredentials
    {

        private string _UserName;
        private string _PassWord;
        private string _DomainName;
        public CustomReportCredentials(string UserName, string PassWord, string DomainName)
        {
            _UserName = UserName;
            _PassWord = PassWord;
            _DomainName = DomainName;
        }
        public WindowsIdentity ImpersonationUser
        {
            get
            {
                return null;  // not use ImpersonationUser
            }
        }
        public ICredentials NetworkCredentials
        {
            get
            {

                // use NetworkCredentials
                return new NetworkCredential(_UserName, _PassWord, _DomainName);
            }
        }
        public bool GetFormsCredentials(out 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;
        }
    }


这个是微软的论坛上看到的认证的一个类
C# code

Microsoft.Reporting.WinForms.IReportServerCredentials ir=new CustomReportCredential("username","pwd","domain"); 
this.reportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/reportserver");
this.reportViewer1.ServerReport.ReportPath = "/无标题";
this.reportViewer1.ServerReport.ReportServerCredentials = ir;


调用的方法,但这个代码提示两个错误

错误 1 无法对属性或索引器“Microsoft.Reporting.WinForms.ServerReport.ReportServerCredentials”赋值 -- 它是只读的

错误 2 无法将类型“Microsoft.Reporting.WinForms.IReportServerCredentials”隐式转换为“Microsoft.Reporting.WinForms.ReportServerCredentials”。存在一个显式转换(是否缺少强制转换?)






------解决方案--------------------
传说中的沙发