2010-10-27 113 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