Results 1 to 10 of 10

Thread: Losing Session (annoying me!)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Exclamation 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

  2. #2
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Post

    I've eperianced that as well.

    I think the solution requires the use of a GUID, and you have to pass the GUID between pages.

    I suggest doing a search for GUID and working in that direction.
    ~Peter


  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    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?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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?

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    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.

  6. #6
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276

    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.
    "Your worst days are never so bad that you are beyond the reach of God's grace...
    and your best days are never so good that you are beyond the need of God's grace."

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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...
    Last edited by Patch21; Jan 7th, 2005 at 12:46 PM.

  8. #8
    Junior Member
    Join Date
    Dec 2004
    Posts
    23

    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

  9. #9
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    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"/>
    Magiaus

    If I helped give me some points.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width