Losing Session (annoying me!)
Hi there
I've come across this problem before, and by searching on the net for a solution I can see that many other people have also. I've searched everywhere and I can still cannot find a solution for it.
This is whats happening:
I log into my web app thru a simple login screen. When the user clicks 'login' I validate the user, add them to the session (Session.Add(User, UserID)), and then response.redirect them to the next page. On the next page I can find the session no problem. From there however, I have links to other .aspx pages. All these links are asp:linkbuttons and the only code behind them is a response.redirect(nextpage.aspx). On these next pages I lose the session. It just clears itself for no apparent reason. On the odd occasion it exists though ! This is seriously annoying me. It only happens on the server where I've uploaded the site too, it does not lose the session on my local machine.
The two common issues I've found on the net with this problem is that either the aspnet_wp process is resetting itself (probably by modifying the bin folder, which I do not, it only contains my dll), or the response.redirect is stopping the asp.net session cookie from being sent from the client to the server when I add the user to the session.
Help !!
Thanks
Patch
Re: Losing Session (annoying me!)
Couple of things I can think of - one of which you mantioned. The worker process could be bombing for some reason - perhaps high load or something?
Another possibility would be that there is a very low timeout set?
Re: Losing Session (annoying me!)
thanks for the replies...
MrGTI - are you talking about the SessionID that is attached to the URL? I did this by changing the cookieless attribute to true in the web.config, but this didnt work :( It's strange, when no session is found the page is redirected to another form, however that SessionID is still in the URL. If the session is lost, shouldn't it not be there?
plenderj - I dont see why the worker process would bomb as I am merely redirecting to a new page, and I am not sending any large data to the server so high load should not be a problem. Is there any way I could check if it is bombing on the server?
Re: Losing Session (annoying me!)
Is the server running in a web farm or web garden mode? If so, I know that session isn't shared between processes. So if you have multiple processors running a worker process, those processes don't share session. Same as if you have multiple machines. The reason is you can't guarentee what process you come in on when you make a request to the server. You can get another process that doesn't contain the session variable you put in the other process.
The only true way to guarentee to share session state, if this is your problem, is to store session data in a shared database each process can hit for session.
Re: Losing Session (annoying me!)
As plenderj pointed before, did you check on the timeout values (both in IIS and the web.config)?
As for multiple web servers, the load balancers could be configured to use Sticky Sessions...
Thanks
Jemima.
Re: Losing Session (annoying me!)
okay...
I've messed around a bit more and changed all my asp:linkbuttons to normal html links, and now it still loses the session on any postback, even if there is no response.redirect.
If I keep on postingback on the same page response.writing the session.count, most of the time it returns a 0, but sometimes it returns a 1. So I am guessing the problem is what hellswraith said earlier about the web farm. It looks like sometimes the request uses the process that is storing my session, while the other times it is using another process.
Would I be right assuming this?
I'll give them a call monday morning to try sort this out.
Thanks for the help so far.
I have checked the timeout in the web.config and it is 20min. For the timeout in the IIS I am not sure...
Re: Losing Session (annoying me!)
I'm having the same problem. I set the timeout to 20 in web.config. I think I might have to change something in global.asax, I'm not sure. Can you tell me how you solved the problem. :)
Thanks
Re: Losing Session (annoying me!)
Ask about these modes.
This one makes Session like ViewState meaning everything has to be able be to serialized, but it keeps state in a farm.
Code:
<sessionState mode = "StateServer" stateConnectionString = "ip:port"/>
XOR
My host laughed at me when I asked about this.
Code:
<sessionState mode= "SQLServer" sqlConnectionString = "data source=blah;id= blah;pw=blah"/>
Re: Losing Session (annoying me!)
I solved the problem by switching to cookies. It took a bit longer to change all the code from sessions to cookies, but it was worth it in the end. I know cookies do have some extra issues that come with them, but it's much easier than having to figure out whats wrong with the session objects seeing as the hosting firm is so hard to get hold of, and when I do their support is clueless :(