Vb.net Microsoft报表查看器登录失败
我正在使用Microsoft report viewer构建asp.net web应用程序。它使用集成安全性连接到SQL数据库。但是,当我在将报表页面发布到服务器后首次加载报表页面时,在本地一切正常,出现以下错误:Vb.net Microsoft报表查看器登录失败,vb.net,Vb.net,我正在使用Microsoft report viewer构建asp.net web应用程序。它使用集成安全性连接到SQL数据库。但是,当我在将报表页面发布到服务器后首次加载报表页面时,在本地一切正常,出现以下错误: An error has occurred during report processing. Exception has been thrown by the target of an invocation. Login failed for user 'SERVER NA
An error has occurred during report processing.
Exception has been thrown by the target of an invocation.
Login failed for user 'SERVER NAME REMOVED'.
奇怪的是,当我点击报告上的刷新按钮而不是IE的刷新按钮时,它的加载情况很好。我知道登录不适用于数据库服务器,但为什么报表查看器不使用我在web.config中设置的集成安全性 您需要实现IReportServerCredentials接口,请参见以下实现:
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;
}
}