I have a weird problem here I can't really place. Maintaining session state was never a problem with VS2003 but after the conversion to VS2005 I have session state problems.
I put a value in the session state in the !IsPostBack in Page_Load. After that if statement I take out that variable again just to test if it is in the session state. This goes ok for the first time I work with th e application. If I then close the browser and go to it again this fails. After the postback the webapplication doesn't enter the !IsPostBack if statement but the variable is also not in the Session state???
This happens every other time. First time running the webapplication-->OK ; Second time running the webapplication-->FAIL; third time-->OK;fourth time-->NOT OK.
This behaviour started after conversion to VS2005 but what even controls such a strange behaviour? What can go wrong after a postback that 50% of the time the Session state is lost?
PS: behaviour happens on the VS2005 internal webserver and IIS 6 and I have tons of memory. So I doubt it's the webserver causing this.
PulsatingQuasar:If I then close the browser and go to it again this fails.
You are suppose to lose Session after the browser is closed.Cheers,Kevin Jones
0 vcsjones8/29/2006 11:42:08 PM
I know. That's not what I meant.
After I open the browser again(second time) a new session will start and offcourse the variable will be put in the session state again in the !IsPostBack if. But if I then do a postback the session state is lost. And this happens every other time.
If I then open the browser a third time the variable is put in the session state again ofcourse and after doing a postback it is still there as expected.
The fourth time I open the browser the variable is put in the session state( just as before); then doing a postback and the session state is lost again.
Nothing fancy is going on and this behaviour started right after conversion to VS2005.
I now see that between clicking a button on the form to initiate the posback and before the breakpoint in the Page_Load the application seems to crash.
I just noticed this because my application created directories for each Session and these directories are cleanedup in the Application_Start in global.asax. I just noticed that sometimes after a post back these directories were gone. This can only happen in Application_Start which would mean a crash in the application. But why there is no exception???????
OK, I have found out what causes it but haven't found out why!
I have 2 applications. One behaves and the other doesn't. I suddenly noticed that I clean directories with the application that behaves itself in the Application_Start and I clean directories in the misbehaving application in Session_Start. That was actually a mistake but I don't understand why cleaning directories in Session_Start is such a problem and why the problem manifests itself after the first postback and why there is no exception informing you that the application had to restart.
Ah. That explains it. That is because if you change any file in the Application Directory in ASP.NET 2.0 the AppDomain is reststarted. In the .NET Framework 1.1, it was just the bin directory that caused that behavior.Cheers,Kevin Jones
0 vcsjones8/30/2006 2:12:49 PM
Wait a minute!!!!
For both webapplications I have a storage directory outside the application directory and an upload directory inside the application directory.
If I move that upload directory elsewhere I can cleanup files from Session_Start aswell without an AppDomain restart????
Is there also a way to tell runtime to not do that for every file and go back to 1.1 behaviour? Cleaning directories at every session_start might also be nice to keep
the garbage collecting down.
Hmm, is there anything in the Event Viewer that might indicate a problem?Cheers,Kevin Jones
0 vcsjones9/2/2006 4:37:22 PM
I could quickly test if not deleting files in the Upload directory makes a difference. If so then it must be what you said. That all files in the application directory are monitored and if changed the appdomain restarts.
OK, I tested it. First I removed cleaning of files in the upload directory. The application continued to work properly.
Then I turned it the other way round( cleaning in the upload directory but not in the download directory). Then it went wrong again. It seems you are right!
Should I mark your answer as the answer or.....?
Yes, but let me go ahead and dig around for another solution for you.Cheers,Kevin Jones
0 vcsjones9/4/2006 12:04:42 PM
In asp.net 2.0 you loose session as soon as there is some changes to file structure in the virtual directory.
look at this post
Please mark the answer if it helped you
i have the same problem
i've been trying to trackit for so long
I migrated from 1.1 to 2.0 and when i login to my application, and then navigate to another page sometimes i loose the session and sometimes i dont!!
I'm in bad need of help