Microsoft ReportViewer and the 'Asp.net Session expired' error
Well, I was trying to use for the first time the Microsoft ReportViewer control. I used some guy's code to translate a DataSet XML to RDLC and ran the app. Everything went OK except for the export to Excel (which was the only real reason why I would attempt using this control). Whenever I tried exporting the report, the 'Asp.net Session expired' error would pop up.
Googling I found these possible solutions:
For a few days, this blog post showed the last solution as working. Then it failed. I don't know why. I fiddled with the RDLC file a little (arranging columns and colors and stuff) and then it seemed to work again. I have no idea why.
I got mad and used Reflector to get the source code for the ReportViewer control and see where it all happends and why! I have found the following:
This reminded me of the time when I was working on a Flash file upload control and I used a HttpHandler to get the flash file from the assembly. Back then the control would not work with FireFox and some other browsers which would use different sessions for the web application and for getting the Flash from the axd http handler.
This time it works with FireFox and IE, but it fails in debug mode and only in IE. I am using IE8, btw.
My conclusion is that
Googling I found these possible solutions:
- set the ReportViewer AsyncRendering property to false - doesn't work
- use the IP address instead of the server name, because the ReportViewer has issues with the underline character - doesn't work, albeit, I didn't have any underline characters in my server name to begin with
- set the maximum workers from 2 to 1 in the web.config (not tried, sounds dumb)
- setting cookieless to true in the web.config sessionState element - it horribly changed my URL, and it worked, but I would never use that
- setting ProcessingMode to local - that seemed to work, but then it stopped working, although I am not using the ReportViewer with a Reporting Services server
- Because towards the end I've noticed that the problem was not an expiration, but more of a Session communication problem, I tried setting machineKey in web.config, although it doesn't work for the InProc setting. So it didn't work either.
For a few days, this blog post showed the last solution as working. Then it failed. I don't know why. I fiddled with the RDLC file a little (arranging columns and colors and stuff) and then it seemed to work again. I have no idea why.
I got mad and used Reflector to get the source code for the ReportViewer control and see where it all happends and why! I have found the following:
- the error message looks like this:
ASP.NET session has expired
Stack Trace:
[AspNetSessionExpiredException: ASP.NET session has expired]
Microsoft.Reporting.WebForms.ReportDataOperation..ctor() +556
Microsoft.Reporting.WebForms.HttpHandler.GetHandler(String operationType) +242
Microsoft.Reporting.WebForms.HttpHandler.ProcessRequest(HttpContext context) +56
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 - the error occurs in the constructor of ReportDataOperation:
public ReportDataOperation():
this.m_instanceID =
HandlerOperation.GetAndEnsureParam(requestParameters, "ControlID");
this.m_reportHierarchy =
(ReportHierarchy) HttpContext.Current.Session[this.m_instanceID];
if (this.m_reportHierarchy == null)
throw new AspNetSessionExpiredException(); - the Session object that makes the error be thrown is set in the SaveViewState() override method in ReportViewer
- Apparently, the error occurs only sometimes (probably after the HttpApplication was restarted and during the debug mode of Visual Studio).
This reminded me of the time when I was working on a Flash file upload control and I used a HttpHandler to get the flash file from the assembly. Back then the control would not work with FireFox and some other browsers which would use different sessions for the web application and for getting the Flash from the axd http handler.
This time it works with FireFox and IE, but it fails in debug mode and only in IE. I am using IE8, btw.
My conclusion is that
- the ReportViewer control was poorly designed
- the ASP.Net Session expired error is misdirecting the developer, since it is not an expiration problem
- the actual problem lies in the inability of the ReportViewer control to communicate with the HttpHandler.
- The problem also could be related to the browser using separate threads to get the application and access the HttpHandler.
Comments
Yes I have tried changing it to state server mode in web.config but I was still seeing the error.
NivedithaHave you looked at these: https://forums.asp.net/t/1238835.aspx?Asp+Net+session+has+expired+in+reportviewer+control there are some ideas there that are not captured in my post.
SideriteI am embedding SSRS reports into asp.net mvc and I see this issue of session expired. I tried so many solutions that are posted on the web but none worked.
NivedithaSomething like this? http://alachisoft.com/blogs/asp-net-session-state-configuration-for-web-farms/ I don't know. I haven't been using ASP.Net for a long time and neither should you :) I think there are better solutions to export to Excel, too, nowadays. I wrote this post 11 years ago! Good luck!
Sideritehow do you do that? Did you ever solve that issue? I am getting the same error even after I deploy my code into the servers. Its occasional but its annoying. I have tried everything just like you did but no luck.
NivedithaI don't think I will find a solution. I've switched from ASP.Net to WPF for now. Are you sure the problem is not affecting you only in debug mode, as it did me?
Sideritehi Sid, I am having the same problem.it is not working in production also.Please let me know your final fix for this problem. Thanks,
--- D ----Hi, I am having a similar problem. ASP.NET Session expired. I understood the explanation you have given. I deployed the application in server farm and still report viewer is not working. It still gives the same error. I have to deploy some reports to the client. Please help me in this regard if you find any solution. I am developing the reports in VS2008 using a dataset.
AnonymousHi, I have a similar problem, the control is in asynch mode, and the dataset is filled with enough rows to generate not more then one page, it works the first time always but when we run the same report gain the session seems to freeze and nothing happens. In another fresh session it works fine for the first time again.
SubsWell, just don't debug it :) It will work in production. And if you are using web farms, you need to synchronize the session between machines.
Sideritehey so how did you fix the issue?
asha-seattle-marathon