Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 3 weeks later...
Posted

Session variables

 

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.

  • 4 weeks later...
Posted
It is kind of strange' date=' 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.[/quote']

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?

Posted

Session Variables issue

 

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.

Posted

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...

 

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

Posted

Session Variables issue

 

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...

 

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.

Posted
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?
Posted

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"

/>

Posted
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.

Posted

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??

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...