Session Variable Loses Value While Session Still Active

VWD 2005 Express.  Visual Basic.

I am running into a situation that when I leave my session unattended, say for 20 minutes, and return to the session and navigate to another page on my site, I get an error when the code behind that page tries to access a session variable that was set when I logged on the session (Session("UserRole")).  If I navigate back to my home page first (where the session variable is first set in a section of code that runs if not a pastback), then the ession variable gets reinitialized and then I am okay.  Why am I losing the value in the session variable when my session sits idle for a while (the session variable only gets assigned in the pageload of my home page, and this should only have to happen once)?


Dr. Douglas Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
0
Chaplain
2/8/2008 5:30:45 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

7 Replies
805 Views

Similar Articles

[PageSpeed] 20

Basically I want my session and session variables to time out at the same time.  If they do time out, I want the session automatically ended and a login required.  At present this is not happening.  My session variables are timing out without the session being logged out.  Any help will be appreciated.  Thanks.


Dr. Douglas Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
0
Chaplain
2/8/2008 5:59:16 PM

There is a default timeout(20Minutes) property for session objects. 

use Session.Timeout=30; to make it to 30minutes. 

use Session.Abandon to end the session. 

In the page_load even check if Session is null like:

if(Session["obj"]=null)

{

Response.Redirect("Login.aspx");


as simple as that
0
eltonlivera
2/8/2008 5:59:25 PM

Where do I put these?  I know I can put the following in the web.config:

<sessionState timeout="30"/>

I assume this is the same as your Session.Timeout=30.  I do not see an equivalent for Session.Abandon.  So where would I put these?  Thanks.


Dr. Douglas Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
0
Chaplain
2/8/2008 6:09:38 PM

Chaplain Doug:

Basically I want my session and session variables to time out at the same time.  If they do time out, I want the session automatically ended and a login required.  At present this is not happening.  My session variables are timing out without the session being logged out.  Any help will be appreciated.  Thanks.

Just check if Session is null in your page load even and redirect it if null.

Session.Abandon is to forcefully end a session. U have to put it in the .CS file
 


as simple as that
0
eltonlivera
2/8/2008 6:28:09 PM

VB does not recognize If Session("UserRole")=Null Then . . .  It does not recognize Null.  Moreover, if the session variable does not exist how can we do a check without getting an error for trying to reference a nonexistent variable?  Finally, I do not have a login.aspx, as I use Basic Authentication (AD).  The login prompt will not come up unless the person has been logged off.  I find that using Session.Timeout=20 simply times out the session after 20 minutes but DOES NOT log off the person.  Hence, redirecting them to my default.aspx page will not produce a login prompt.  So my real issue is, how can I make the site log off the person when the session times out?

 

P.S.  I am still a novice and don't even know what the .cs file is.


Dr. Douglas Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
0
Chaplain
2/8/2008 6:45:28 PM

I am also new to ASP.NET.

C#  source files have a .CS extension. In your case it should be .vb since you are using VB.


 


as simple as that
0
eltonlivera
2/8/2008 6:53:45 PM

Use the following:

If Session("sessionObject") Is Nothing Then


Mark this post as the "Answer" if it was the answer.
0
sswanner1
2/8/2008 8:43:30 PM
Reply:

Similar Artilces:

getting a new session id and losing session variables
prb: I have two pages in my app - one on redirect and the other as a new window - that get a new session id from every other page in the app (they both get the same session id) and obviously the session state variables are lost and, therefore, the pages do not look like they should.  All pages are within the same domain and virtual directory. 1. a redirect; session variables are lost; session id is different from the previous page; if you click the BACK button you return to the previous page and the session id is the same as before and the session variables are as they should be2. ...

How to get session variable value into a static variable
Hi, On page preinit i am adding few session variables. Now i want to retrive these session variable values into my static variables. protected void Page_PreInit(object sender, EventArgs e) {Session.Add("T", "Default"); Session.Add("T1", "Red"); Session.Add("T2", "Blue");   }   i have few static variables which shud contain these vaules.  public string TT; public string TT1; public string TextForeColor =sess = "#FFFFFF";   i want to get T value into TT ... T1 into TT1..and so on &n...

After a looong night managed to change Session mode from inProc to SQLServer but still can't get the session variables to be saved
Hi,  I ran my Shopping Cart project and somehow everything worked fine(while in inProc), session variables were saved fine. I made some changes to my project and since then keep getting null session variables, no matter what I do. It took me the whole night to figure out how to turn to SQLServer mode,  marked custom classes as 'Serializable' with [Serializable] before the class definition but everything's in vain. Getting the same damned 'nulls' instead of the saved objects. private void Page_Load(object sender, System.EventArgs e)         {...

I called Session.Abandon, why are my session variables still there?
I called Session.Abandon, why are my session variables still there? While you might call Session.Abandon at the top of the page, any existing session variables will not actually be destroyed until the page goes out of scope. So if you have a page like this:       Session("a") = 1     Session.Abandon     Response.Write(Session("a"))  You will see "1" output to the screen, even though the variable was accessed after you called Session.Abandon. When the user navigates to another page, however,...

Session Variables (Get values)
Hi, I am storing some variables in Session, Double values, Integers and Strings.Sometimes these values can be null or empty (""). While retrieving these values from session I will declare a variable of its type. Let say for example I want to get a Double value from Session. Dim dblAmount as DoubledblAmount = Session("sessAmount") Here I am getting trouble when value is empty, its giving an errorConversion from string "" to type 'Double' is not valid. How to handle this kind of situations? Let me know your suggestion. Thanks   Hi. Before assigning the value, check if the session...

Getting value out of session variable
 Hi,How to get the value of a session. It is storing the dataset value. I dont know how to transfer that to a variable.   private SearchDotnet.Searchs.UserSearch sSite;  if ((sSite == null))          {             sSite = Session["Site"];           }         }  The thing is sSite is  delcared as above. I need to unload the session variable to sSite. Have not found a...

Session Variable losing its value
 I have a drop down list that that binds to a detailsview and populates a Label based on selectedindexchanged. At the very end of the selectedindexchanged method I set a session variable = to the Label.Text. I've validated that the data is correct at that point. However, once I go to another content page the session variable is empty. Session("System") = lblSys1.Text      (I have a breakpoint after this and have validated the value is there)I also have a breakpoint in the Page_Load event of another content page so I can check the value of Sess...

getting value of session variable
I'm trying to display the value of a session variable in a label. I know the session variable exists because in my page load event I redirect the user to a different page if it's value is null. I want to display it's value in a label to test some things, but I keep getting an error whenever I try.  Here is my code:   Label:<asp:Label ID="lblSessionTest" runat="server" Text="Label"></asp:Label>  How I'm trying to display it (in my page load event):  lblSessionTest.Text = Session("loggedIn"); &nbs...

session variables losing values
hi i am using global.asax file for storing my session values. but they are losing thier values frequently. i am not using any web.config file or some thing like that. just an asax file and my aspx files. i installed service pack 2 for .net also. but the problem is still exits. can any body tell me how to handle this problem. thanks if .Net consumes a lot of memory (60% or more by default), your app will get restarted which will destroy the sessions. Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.c...

How to get session variable values in webpart?
Anyone know that how to get session variable values in webpart? I developed a ASP.NET page to accept a input order code e.g. "E923829" and set it as session variable for the following working page. One of the working page is containing a webpart to show this order summary e.g. number of items and total price. I'm using VB.NET to develop this webpart. I'd tried to use Dim OrderNumber as string = Page.session("ORDER_NUMER"). But this will cause error while loading the webpart. Your advice will very appreciated....

How to include a session variable assigning a value to session in javascript function
I have the following javascript function which is in my .net project under .js file where all the javascript functions are residing: Can you please tell me how i can assign a value to session("Comesfrom") = 'CO'   How i can include the session("ComesFrom") = 'CN' in the following Javascript function. <code> function openProg(message) { if (checkOpen(message)){ parent.frames("mainFrame").location = "ccsNetAdminFind.aspx"; } } </code>   Thank you very much. You can't.  Session values are set and stored server-side, and that JavaScript runs client ...

When does Session.Abandon remove session variables (.NET 1.1)?
I have a logout function which includes session.abandon. This also (correctly) removes any session variables I've created if I look at them on the next page load. However, if I examine these variables immediately after the session.abandon call, they still exist with their current values. Where in the page life cycle does session.abandon actually remove these variables? Thanks in advance.  -- ZLA  After you have called Abandon() method, current session becomes invalid, but new session will be created on the next request. If you need to remove all values from session coll...

Getting a session variable value in Servlet
Hi, I am using psSession to set and get session variables in PowerDynamo scripts. I also had to use servlets for serving some of the pages. I want to access the session variables I have set in PowerDynamo scripts from my servlet. I tried session.getValue from my servlet. But it returns a null in servlet. Any ideas as to how I can get the values of session variables in my servlet? TIA, Mani. Mani, I would think that because they are two different session types you could not do this. A workaround would be to create a cookie that you can use from either spot Scott ...

Session-to-session
I must be missing something. I can not get the tabs to come back as they were when a session is ended. On the Main tab, I have "Show my windows and tabs from last time" On the Privacy tab, I have "Always clear my private data" with ONLY Download History, Cache, and Authenticated Sessions selected. When I close a session and then restart Firefox, I only get a single blank tab. -- The Frosted Flake +------------------------ SPAM is for eating ------------------------+ Frosted_Flake wrote: > I must be missing something. I can not get the tabs to come...

Web resources about - Session Variable Loses Value While Session Still Active - asp.net.getting-started

Variable - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Westpac interest rate rise is one of many variable loan rate rises
WESTPAC is not alone in hitting its owner-occupier customers with a surprise interest rate rise, as dozens of other variable rate home loans ...

Airbnb upgrades variable pricing tool for hosts
Online home rental group Airbnb is rolling out an upgraded variable pricing tool that automatically raises or cuts room rates based on supply ...

Commonwealth Bank raises variable home loan rates
Home owners' mortgage costs are set to rise by hundreds of dollars a year, after the Commonwealth Bank became the latest bank to hike interest ...

CBA lifts variable home loan rates to offset costs associated with stricter capital requirements
The Commonwealth Bank to lift its home loan interest rates independently of the Reserve Bank to partially offset costs associated with stricter ...

Washington Square Signs Spielbergs, Choi Joins Variable and More
... films and an episode of the HBO comedy series "Girls," on which he plays the role of Ray Ploshansky. New York-based creative collective Variable ...

YouTube v10.32 Tweaks Some Interface Elements And Includes Hints About Virtual Reality Content And Variable ...
Forget Update Wednesday! Monday is the new big day. Not only were we treated to the latest M preview release and the official Marshmallow name, ...

"You have to ignore many variables to think women are paid less than men. California is happy to try." ...
Writes Sarah Ketterer in The Wall Street Journal in "The ‘Wage Gap’ Myth That Won’t Die" (which you can get to without subscribing if you Google ...

Cisco Debuts Open Pay Variable Pricing, Updates CCRE
Cisco Debuts Open Pay Variable Pricing, Updates CCRE Channel Partners Kris Snow, president of Cisco Capital, says the company's new Open Pay ...

Expert Reveals the Latest Variable Capacity Technology
Learn about gForce Ultra CRAC equipment, the latest variable capacity technology to lower energy usage and increase reliability.

Resources last updated: 12/15/2015 6:45:09 AM