Reputation: 31
I have a asp.net(VS2010 - .NET 4.0) applications deployed on Windows Azure. I am trying to use .NET report viewer control. I am running the reports in Local Mode. Reports work fine and gets displayed correctly. When i try to export it to Excel/PDF/Word i get this error "ASP.NET session has expired or could not be found".
Here is my Sample Code : ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RxCloudReports.Default" EnableSessionState="True" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
</script>
</head>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Local" SizeToReportContent="true" AsyncRendering = "true"
ShowPageNavigationControls="true" ShowExportControls="true" ShowToolBar="true" >
</rsweb:ReportViewer>
</form>
</body>
</html>
C#
DataSet ds = GetDataSet(_ID, _Module);
ReportViewer1.Reset();
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = "Reports/Reports1.rdlc";
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ReportDS", ds.Tables[0]));
ReportViewer1.LocalReport.Refresh();
Upvotes: 3
Views: 20609
Reputation: 117
In my case; the ReportViewer control living in iframe an everything works fine, but in recent days my web site has stopped working, the reason was the google chrome security updates; Solution was set a subdomain for my report server, I.E. my web site living at https://app.myapp.com my report server living at https://reports.myapp.com.
NOTE: This solution is only applicable if you use an iframe for sow the report control and the sites live in different domains
Ref: Developers: Get Ready for New SameSite=None; Secure Cookie Settings Announcement: SameSite Cookie Handling and .NET Framework 4.7.2 Patch Availability on Azure App Service
Upvotes: 1
Reputation: 1236
There is another situation in which the 'ASP.NET session expired' error can occur, besides web farms, worker process cycling, actual expiration of the session etc.
This situation was extremely aggravating and I did not see an answer posted for it on Stackoverflow so if this was to happen to someone else this will hopefully shorten the pain.
This situation can occur in any application that uses an embedded report viewer control, but it manifests itself faster if you have an application with multiple embedded report viewer controls that are refreshed frequently.
What happens is the report viewer controls keep creating new cookies (not sure why) every time they are refreshed. The cookie names have a suffix of _SKA.
Since every browser has a limitation on the number of cookies they will store (for most recent IE versions it is 50, for Chrome and Firefox it is a larger number but still finite), the cookies build up until the limit is reached at which time the browser starts discarding the oldest cookies, which means the session cookie for ASP.NET ends up being discarded, causing the ASP.NET session expiration error.
So in this situation it has nothing to do with a session expiring, or anything on the server side. It is the client side browser that starts discarding the oldest cookies when the browser cookie count limit is reached.
I came onto this as a solution from this question in which the cookie limit issue causes another issue. The code below is based on the solution in that question: SSRS: Why do SKA-cookies build up until: HTTP 400 Bad Request - Request Too Long
Adding this code to the global.asax will solve the issue:
void Application_BeginRequest(object sender, EventArgs e) {
if (Request == null || Request.Cookies == null) {
return;
}
if (Request.Cookies.Count < 10) {
return;
}
for (int i = 0; i < Request.Cookies.Count; ++i) {
if (StringComparer.OrdinalIgnoreCase.Equals(Request.Cookies[i].Name, System.Web.Security.FormsAuthentication.FormsCookieName)) {
continue;
}
if (!Request.Cookies[i].Name.EndsWith("_SKA", System.StringComparison.OrdinalIgnoreCase)) {
continue;
}
if (i > 10) {
break;
}
System.Web.HttpCookie c = new System.Web.HttpCookie(Request.Cookies[i].Name);
c.Expires = DateTime.Now.AddDays(-1);
c.Path = "/";
c.Secure = false;
c.HttpOnly = true;
Response.Cookies.Set(c);
}
}
Upvotes: 0
Reputation: 597
I have set
<rsweb:ReportViewer ... KeepSessionAlive="false" />
after this it worked on Azure (for me at least).
Upvotes: 3