Session Problems

FastRodas

Freshman
Joined
Apr 14, 2004
Messages
25
Hi to Xtremers,

i'm having some session problems on my ASP.NET application. I'm a little confused and dont understand what is happening. I'm using CodeBehind.

Every time i redirect to a ASP.NET page the first thing i do is to put the session varibles into some local variable and in the end update the session again with the new values.

public string localVariable;

private void Page_load(object source, EventArgs e)
{
if (!IsPostBack)
{
localVariable = Session["SessioVariable"];
}
}


Sometimes when i click a botton and the ASP.net page does a postback i loose the value on localVariable. i am not sure but i think sometimes the session itself looses it's values. I know the session does not expire so i'm a little lost.

can anyone tell what's happening?

thx to all
 
If you are using your code you will only copy the session variables to local variables when the page isn't a postback - which seems to agree with your quote of
Sometimes when i click a botton and the ASP.net page does a postback i loose the value on localVariable

if you need the variables all the time then put them ouside the if(!PostBack){...} block.
 
Session variables

PlausiblyDamp said:
If you are using your code you will only copy the session variables to local variables when the page isn't a postback - which seems to agree with your quote of


if you need the variables all the time then put them ouside the if(!PostBack){...} block.

It is kind of strange, but I am having a weird problem. After user loged in, I validate user against SQL User table, and store id in SESSION(USERNAME). Next, upon every Page_Init, I check If IsNothing(SESSION(USERNAME)). If it is nothing, I redirect back to Login page. The strange part is that I get redirected to Login page when going between pages. For some reason SESSION(USERNAME) becomes NOTHING. If any one of you had the same problem, or have any ideas, please let me know. Thanks.
 
alemargo said:
It is kind of strange, but I am having a weird problem. After user loged in, I validate user against SQL User table, and store id in SESSION(USERNAME). Next, upon every Page_Init, I check If IsNothing(SESSION(USERNAME)). If it is nothing, I redirect back to Login page. The strange part is that I get redirected to Login page when going between pages. For some reason SESSION(USERNAME) becomes NOTHING. If any one of you had the same problem, or have any ideas, please let me know. Thanks.
I did have this problem. I guess that's because the session expires in like 20 mins. I changed the sessionstate timeout setting in the web.config file and set it to 60 mins. It's working alright now. There was this another method that I'd read about somewhere where you set the timeout of all your session variables on the first page of ur site. It's using the following method Session.Timeout=x (mins) but that did not help though :(

anybody else can throw some light on this?
 
Sometimes I lose the session when I refresh, even tho my session is set to 60 minutes. Or I lose it when I click to go to another page...

any ideas why?
 
Session Variables issue

praveensg said:
I did have this problem. I guess that's because the session expires in like 20 mins. I changed the sessionstate timeout setting in the web.config file and set it to 60 mins. It's working alright now. There was this another method that I'd read about somewhere where you set the timeout of all your session variables on the first page of ur site. It's using the following method Session.Timeout=x (mins) but that did not help though :(

anybody else can throw some light on this?

Actually, this happens withing timeout range. So timeout is not an issue. It happens when I go from one page to another within 20 min timeout.
 
Yes, from the same application..

My issue is exactly like Alemargo.. going page to page within the 60min (in my case) timeout, or refresh or logout..

This is how I do it: at the begining of each page, in PageLoad, I do a "checksession" and if the variable is empty, I reroute to a "session timeout" page...

Code:
Private Sub checkSession()
        If IsNothing(Session("ContactSelected")) _
          Or IsNothing(Session("userid")) Then
            Response.Redirect("SessionExpired.htm")
        End If
    End Sub
 
Session Variables issue

eramgarden said:
Yes, from the same application..

My issue is exactly like Alemargo.. going page to page within the 60min (in my case) timeout, or refresh or logout..

This is how I do it: at the begining of each page, in PageLoad, I do a "checksession" and if the variable is empty, I reroute to a "session timeout" page...

Code:
Private Sub checkSession()
        If IsNothing(Session("ContactSelected")) _
          Or IsNothing(Session("userid")) Then
            Response.Redirect("SessionExpired.htm")
        End If
    End Sub

Yeap, that is what I have. I do check it in the same manner.
 
Yeah right. That used to happen to me within the timeout itself. I set the Session.TimeOut function to 60 but even then it used to happen. So I changed the setting in the web.config file. I think it has stopped now. I am not sure. So how are you guys setting the timeout threshold? In the Web.Config file or in the first page?
 
I have mine in Web.config.. I only changed the "timeout" value and left the rest as is ..didnt change IP stuff in there.. ..would that be causing it??

This is what I have:

<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="60"
/>
 
eramgarden said:
I have mine in Web.config.. I only changed the "timeout" value and left the rest as is ..didnt change IP stuff in there.. ..would that be causing it??

This is what I have:

<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="60"
/>
I am not really sure now. Maybe some of our more knowledgeable Xtremers might help us figure this out. I don't want to risk it because my project has data entry screens that take like 20-25 minutes to fill in :) This would be a real handicap when you enter data for 20 minutes, you hit save and it takes u to the login page.
 
Does it seem to expire after a consistent time or do the session variables seem to be lost on a random basis?
Also, just out of interest what OS are you running the web application on?
 
Happens on random basis...

I have VS.Net 2002, with Framework 1.0 (if this makes a difference).

I'm developing on Windows2000 Professional. I have my laptop and another testbox and session times out randomly on both.

But one thing i so which I'm not sure I should be doing... In my sideMenu's code behind, I clear some sessions by setting them to "string.empty". I do that because I want the session variable to be reset..just like reseting a variable.. so when user clicks on a sidemenu, i clear out the previous session Should I be doing this??
 
Sounds odd - probably not what you wanted to hear :-\
when the session variables are being reset is this happening to all session variables or just selected ones? If it is happening to all sessions then there could be a problem that is causing the asp.net service to restart itself.
Are there any errors / warnings logged in the Event Viewer that would indicate the asp.net service is restarting (look for references to aspnet_wp.exe).

Alternatively you may want to look at storing the session state outside of the Asp.Net process. (Have a look here for further info.

As another idea do you have any service packs for the framework installed? If not it may be worth checking out SP2 - in the List of fixes it mentions the worker process restarting unexpectedly as one of the fixes.
 
Reseting them for specific session variables..

but let me look into the sites you sent me and see if they would help.

Thanks. Will post again if still have issues.
 
Back
Top