收到错误:
“属性或索引器 'Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials' 无法分配 - 它只读“
在这一行:
reportviewer1.ServerReport.ReportServerCredentials.NetworkCredentials =新的System.Net.NetworkCredential(“someaccount”, “somepassword”);
当我将光标悬停在NetworkCredentials上时,它会显示:“获取或设置用于使用报表服务器进行身份验证的网络凭据”..
到底发生了什么事?
感谢
答案 0 :(得分:1)
this.rpv.ServerReport.ReportServerCredentials不是只读的。阅读这篇文章:
答案 1 :(得分:0)
它仍然是只读的,ReportServerCredentials字段仍然是只读的,它只有getter而不是setter!
答案 2 :(得分: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;