[英]Request failed with HTTP status 401: Unauthorized on second try
我有一个SSRS报告,并且正在我的Web项目中调用此报告。 我的客户端页面如下图所示:
我的.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(索赔(付费))项目上单击左侧树视图并输入开始日期和结束日期时。 报告工作正常。 现在,假设在此之后,我单击任何其他项,例如Claim(ALL),然后再次单击(Claims(Paid))并提供相同的日期参数,这将显示以下错误:
请求失败,HTTP状态为401:未授权。
如果我将其部署在IIS上并尝试运行,它将显示此错误:
如果您已到达此页面,则是导致AFS Claims显示它的错误。 尽管我们会尽力确保您的用户体验没有错误,但有时我们可能并不了解遇到的错误。
请在浏览器中选择“后退”按钮,并查看您尝试使用的最后一页。
请注意:为了安全起见,即使您已选择要记住登录名的复选框,登录的用户在此网站上也有一个会话时间限制。 如果您超出了会话的超时时间,则很可能您尝试完成的操作将不起作用。
有谁能够帮助我? 为什么它第一次起作用,但第二次却不起作用?
尝试将设置的凭据部分放在ShowReport()方法中,而不放在页面init方法中。 设置一个断点以查看您的第二个请求的凭据是什么样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.