ASP.NET session has expired or could not be found -> Because the Session.SessionID changes (Reporting Services)
Asked Answered
S

11

14

1.-I'm using reporting services and sometimes I get this error ASP.NET session has expired or could not be found when I try to load a report.

2.-I realized that I get this error when the Session.SessionID property changes even though the user is the same. If it does not change, the report is loaded. I mean, if I refresh the report a number of times, whenever the Session.SessionID is the same than the last one, the report is loaded.

3.-Microsoft Documentation says:

When using cookie-based session state, ASP.NET does not allocate storage for session data until the Session object is used. As a result, a new session ID is generated for each page request until the session object is accessed. If your application requires a static session ID for the entire session, you can either implement the Session_Start method in the application's Global.asax file and store data in the Session object to fix the session ID, or you can use code in another part of your application to explicitly store data in the Session object.

If your application uses cookieless session state, the session ID is generated on the first page view and is maintained for the entire session.

The point is that I can not use a cookieless session state because I need cookies.

What could I do to avoid this error? Or What could I do to avoid the Session.SessionID to change on every request?

Semiology answered 29/2, 2012 at 2:15 Comment(0)
E
10

You are probably storing your session InProcess. Try changing it to session state server. You can find more details here.

Emotionalize answered 29/2, 2012 at 4:40 Comment(3)
I had tried changing the session to State Server, but after that I got other error: "Unable to serialize the session state...", so, I wonder how I can make the session state serializable.Semiology
Most likely you are not storing some complex objects in your state, and those objects are not serializable. Make sure all your objects are serializable. Take a look here for a similar problem: #5889740 Take a look here for details about serialization in .NET: msdn.microsoft.com/en-us/library/ms973893.aspxEmotionalize
You were right once more! I did not realize that the Session State was using a special object, so, I just made its class serializable (Using the second link you provided me) and the reports are working fine now... Thank you so much!!!Semiology
S
7

I'm using report viewer 11.0.0; in your web config on system.web section, put the next configuration:

<sessionState timeout ="120" mode="InProc" cookieless="false" />

When you are generating the report (C# code bellow) in the reportviewer object change the KeepSessionAlive property to false and the AsynkRendering property to false, and that's all

        this.rvReporte.KeepSessionAlive = false;
        this.rvReporte.AsyncRendering = false;

(rvReporte) is a ReportViewer control located on my asp.net Form This solution work for me, i hope that work for other people.

Regards

Scanlon answered 20/1, 2015 at 2:33 Comment(3)
worked for me. I didn't need sessionstate modifications.Alloy
how does this affect performance of the report on reloads and interactions?Alcove
According to the docs, with these settings the report will work for 120 minutes and then get a session expired errorAlcove
R
5
<httpCookies httpOnlyCookies="false" requireSSL="false"/>

Solved the problem. Thanks to : http://www.c-sharpcorner.com/Blogs/8786/reportviewer-Asp-Net-session-has-expired.aspx

Romero answered 30/10, 2014 at 5:52 Comment(0)
F
4

I had the same issue on report viewer page when the web site was accessed from outside intranet. hardvin's suggestion saved the day for me which is to set this.rvReporte.KeepSessionAlive = false; this.rvReporte.AsyncRendering = false;

I changed the property on the control itself. I am using report viewer on a user control which raises a custom event for supplying parameters programmatically at the host page instead of prompting the users.

Filamentous answered 14/5, 2015 at 21:27 Comment(0)
F
2

I solved this issue by setting AsyncRendering to false on reportviewer server control

Fallonfallout answered 2/6, 2016 at 23:43 Comment(0)
E
2

Having the reportviewer being displayed in iframe was giving us this error. If displayed outside of iframe it works nice. The reportviewer object has this configuration, AsyncRendering = false and KeepSessionAlive = true.

The webapp that has the reportviewer and set the session cookie in the browser was compiled with .net framework 4.6.1. We upgrade to 4.8 and put this in web.config

<sessionState cookieSameSite="None" />
    <httpCookies requireSSL="true"/>

Só the solution is from https://learn.microsoft.com/en-us/aspnet/samesite/system-web-samesite#:~:text=The%20updated%20standard%20is%20not%20backward%20compatible%20with,SameSite%3DStrict.%20See%20Supporting%20older%20browsers%20in%20this%20document.

Epigeous answered 20/5, 2021 at 14:35 Comment(1)
That fix my problem :) all other solution didn't work when i use IFrameBellinger
S
1

The answer given by Alexsandar is just one of the solution to this problem.

This link clearly explains what is the root cause for this problem and possible solutions: http://blogs.msdn.com/b/brianhartman/archive/2009/02/15/did-your-session-really-expire.aspx

In case of Brian, the way he has descrived the problem, if he had just a single IIS server, using a session object in his code would have solved the problem because in that case, the SessionID which is passed in the request from browser to the server will get mapped to a corresponding sessionID on the server and hence the session expiry message will not come.

Setting the mode may only work in case of a server cluster where Brian had multiple IIS servers handling the same request. In that case an out of process mode will help to retrieve the session object from the Session Store irrespective of the server hit.

So based on this observation, I would conclude that Brian's problem was not related to cookies but to a server cluster. The information provided by Brian in his question and the subsequent solution misled me and hence this clarification. Hope it helps anyone looking for a similar problem.

Thanks, Vipul

Soluble answered 5/8, 2013 at 11:24 Comment(0)
F
1

For me Azure hosted web app turning ON - ARR Affinity fixed the issue.

ARR Affinity ON

enter image description here

Fauch answered 21/1, 2020 at 13:18 Comment(0)
D
1

I have added the below-mentioned line on the web config file and it is working fine for me.

<sessionState mode="InProc" cookieless="true" timeout="3000" />
<pages enableSessionState="false" />
<customErrors mode="Off" />
Dumbwaiter answered 12/7, 2022 at 12:7 Comment(0)
T
0

Try removing SessionState="somevalue" tag from the top of your calling ASPX page. I'm using a custom SessionState and refuse to use InProc since I have multiple instances on Azure. You can even use AsyncRendering=True if you desire. Let me know if this did the trick for you.

Tarantella answered 8/8, 2013 at 18:33 Comment(0)
P
0

For me, it turned out to be having more than one worker process for the app pool.

Pointing answered 29/4, 2015 at 18:8 Comment(1)
How does that happen?Alcove

© 2022 - 2024 — McMap. All rights reserved.