我有一個SSRS報告,我在我的Web項目上調用此報告。我的客戶端頁面類似下面的圖像:HTTP狀態401請求失敗:第二次嘗試未經授權
我的.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);
}
我的問題是:1時,當我在左邊樹狀點擊GUI(索賠(付費))項目並輸入開始日期&結束日期。報告工作正常。現在,假設在此之後我點擊喜歡 - 索賠(ALL)的任何其他項目,並在那之後,我再次點擊(索賠(收費)),並給予相同的日期參數它告訴我下面的錯誤:
The request failed with HTTP status 401: Unauthorized.
如果我將部署它在IIS上,並嘗試運行它,它告訴我這個錯誤:
If you have reached this page, there was an error that caused AFS Claims to show it. While we make every effort to ensure your user experience is without error, there are times when the errors encountered may not have been something we know about.
Please select back button in the browser and review the last page you were trying to use.
Please Note: For security purposes, there is a session time limit on this web site for users that are logged in, even if you have selected the checkbox to remember your login. If you have exceeded the timeout for the session, it is quite possible that the action you are trying to complete will not work.
任何人都可以幫助我嗎?它爲什麼第一次工作,但不是第二次?
很高興我能幫到你。 Ssrs在每次通話中都需要一個身份驗證部分。當您的頁面初始化並且報告出現在門外時,您正在設置auth。然而,在此之後,在每個呈現請求之前,Init不會被調用。這可能有很多原因。例如,如果您將響應字節[]加載到div中,或者可能使用iframe。 –