您需要實現IReportServerCredentials
inteface,請參見下面的實現:
public class CustomReportCredentials : IReportServerCredentials
{
protected string _username = string.Empty;
protected string _password = string.Empty;
protected string _domainName = string.Empty;
public CustomReportCredentials(string userName, string password, string domainName)
{
_username = userName;
_password = password;
_domainName = domainName;
}
public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string userName, out string password, out string authority)
{
authCookie = null;
userName = password = authority = null;
return false;
}
public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get { return null; }
}
public System.Net.ICredentials NetworkCredentials
{
get
{
if (_username != "noadmin")
{
return new NetworkCredential(_username, _password, _domainName);
}
else
{
Uri uri = new Uri("http://tempuri.org/");
ICredentials credentials = CredentialCache.DefaultCredentials;
NetworkCredential credential = credentials.GetCredential(uri, "Basic");
return credential;
}
}
}
}
然後你就可以報告查看證書屬性設置爲IReportServerCredentials
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack){
IReportServerCredentials iReportCredentials = new CustomReportCredentials("user",
"mypassword", "mydomain");
ReportViewer1.ServerReport.ReportServerCredentials = iReportCredentials;
}
}
謝謝,這一定是我錯過了。有沒有辦法讓這使用集成安全,而不是我必須設置用戶名/密碼? – user842818