第一步,需要创建一个自定义的Credentails类型

public class CustomReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials
{  

    // local variable for network credential.
    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;
    }

}

第二步,在代码中这样编写

IReportServerCredentials irsc = new CustomReportCredentials(userid,password, domain);
ReportViewer1.ServerReport.ReportServerCredentials = irsc;

相关文章:

  • 2022-01-06
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2021-07-16
  • 2022-02-24
  • 2022-12-23
猜你喜欢
  • 2022-01-31
  • 2022-12-23
  • 2021-05-22
  • 2022-01-09
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案