2010-10-27 76 views
1

收到错误:报告服务网络凭据

reportviewer1.ServerReport.ReportServerCredentials.NetworkCredentials = new System.Net.NetworkCredential("someaccount", "somepassword");

当我将鼠标悬停在NetworkCredentials光标,它说:这条线内

"Property or indexer 'Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials' cannot be assigned to-- it is read only"

“获取或网络凭据用于与报告服务器进行身份验证“..

这里发生了什么?

谢谢

回答

0

它仍然是只读的,即ReportServerCredentials领域还在只读的,它只有吸气而不是setter!

0

这个类添加到同一个命名空间:

public class CustomReportCredentials : 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 System.Security.Principal.WindowsIdentity ImpersonationUser 
    { 
     get { return null; } 
    } 

    public ICredentials NetworkCredentials 
    { 
     get { return new NetworkCredential(_UserName, _PassWord, _DomainName); } 
    } 

     public bool GetFormsCredentials(out Cookie authCookie, out string user, 
     out string password, out string authority) 
     { 
     authCookie = null; 
     user = password = authority = null; 
     return false; 
    } 
} 

然后设置您的凭据是这样的:

IReportServerCredentials Creds = new CustomReportCredentials("Administrator", "password", "domain"); //to actual values 
myReportViewer.ServerReport.ReportServerCredentials = Creds; 
+0

注意这只适用于WebForms控件,而不适用于WinForms。 – 2017-12-09 14:37:33