我有一份SSRS报告,我在我的网络项目中调用此报告。我的客户端页面如下图所示:
我的.cs页面代码是:
public reports()
{
Init += Page_Init;
Load += Page_Load;
}
protected void Page_Init(object sender, System.EventArgs e)
{
ReportViewer1.ServerReport.ReportServerCredentials = new MyReportServerCredentials();
}
[Serializable()]
public sealed class MyReportServerCredentials : IReportServerCredentials
{
public string UserName = ConfigurationManager.AppSettings["rvUser"];
public string Password = ConfigurationManager.AppSettings["rvPassword"];
public string Domain = ConfigurationManager.AppSettings["rvDomain"];
public WindowsIdentity ImpersonationUser
{
//Use the default windows user. Credentials will be
//provided by the NetworkCredentials property.
get { return null; }
}
public ICredentials NetworkCredentials
{
get
{
//Read the user information from the web.config file.
//By reading the information on demand instead of storing
//it, the credentials will not be stored in session,
//reducing the vulnerable surface area to the web.config
//file, which can be secured with an ACL.
if ((string.IsNullOrEmpty(UserName)))
{
throw new Exception("Missing user name from web.config file");
}
if ((string.IsNullOrEmpty(Password)))
{
throw new Exception("Missing password from web.config file");
}
if ((string.IsNullOrEmpty(Domain)))
{
throw new Exception("Missing domain from web.config file");
}
return new NetworkCredential(UserName, Password, Domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie,
out string userName, out string password,
out string authority)
{
authCookie = null;
userName = UserName;
password = Password;
authority = Domain;
// Not using form credentials
return false;
}
private void ShowReport()
{
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri(reportServer);
ReportViewer1.ServerReport.ReportPath = "/xyz/ReportNewname";
ReportParameter[] param = new ReportParameter[8];
param[0] = new ReportParameter("p_ClientID", ClientID);
param[1] = new ReportParameter("p_CarrierID", carrierId);
param[2] = new ReportParameter("p_StartDate", BeginDate);
param[3] = new ReportParameter("p_EndDate", EndDate);
param[4] = new ReportParameter("p_ClaimSubTypeID", ClaimTypeID);
param[5] = new ReportParameter("p_SalesAuditorId", SalesAuditorID);
param[6] = new ReportParameter("p_IsPaid", PaidClaim);
param[7] = new ReportParameter("p_IsOpen", OpenClaim);
ReportViewer1.ServerReport.SetParameters(param);
}
我的问题是:第一次点击GUI(声明(付费))项目的左侧树视图并输入开始日期&结束日期。报告工作正常。现在,假设在此之后我点击任何其他项目 - 如声明(ALL),然后再点击(声明(付费))并给出相同的日期参数,它会显示以下错误:
请求失败,HTTP状态为401:未经授权。
如果我将它部署在IIS上并尝试运行它,它会向我显示此错误:
如果您已到达此页面,则会出现导致AFS声明显示错误的错误。虽然我们尽一切努力确保您的用户体验没有错误,但有时候遇到的错误可能不是我们所知道的。
请在浏览器中选择后退按钮并查看您尝试使用的最后一页。
请注意:出于安全考虑,即使您已选中复选框以记住您的登录信息,此网站也会为登录的用户设置会话时间限制。如果您已超过会话超时,则您尝试完成的操作很可能无效。
任何人都可以帮助我吗?为什么它第一次工作,但不是第二次?
答案 0 :(得分:1)
尝试将设置凭据部分放在ShowReport()方法中,而不是放在页面init方法中。设置断点以查看第二个请求中凭据的外观。