473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Clearing Session Variables

In a "Save and Quit" button on my web app form (aspx), I have the
following code that is supposed to clear a session variable (an user
id) and redirect to a logon page:

Session.Clear()
Session.Abandon()
Response.Redirect("ApplicantLogon.aspx")

1. The redirect occurs, but the session variable does not clear.

2. A related issue that ****worries me greatly**** is that once
redirected to the logon page, selecting the browser's back button,
redirects to the web form on which the user has entered data!

This latter page has code in the onload event that looks for the
session variable assignment, and if it doesn't find it, it is supposed
to redirect the user to the logon page...however, since I didn't suceed
in clearing the variable using the session methods, above, this does
not work...

Can someone educate me?

Thank you.
J.

Nov 19 '05 #1
6 9617
JJ_377,

Regarding ISSUE #2 : When user clicks browser back button, the browser
loads the page and user entered data from local cache. One way to prevent
this is by expiring the local cache as in following sample.

private void Page_Load(object sender, System.EventArgs e)
{
ExpirePageCache();
.............................................
.........
}

/// <summary>
/// This function prevent the page being retrieved from broswer cache
/// </summary>
private void ExpirePageCache()
{
Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.Cache.SetExpires(DateTime.Now-new TimeSpan(1,0,0));
Response.Cache.SetLastModified(DateTime.Now);
Response.Cache.SetAllowResponseInBrowserHistory(fa lse);
}

Sreejith

"JJ****@hotmail.com" wrote:
In a "Save and Quit" button on my web app form (aspx), I have the
following code that is supposed to clear a session variable (an user
id) and redirect to a logon page:

Session.Clear()
Session.Abandon()
Response.Redirect("ApplicantLogon.aspx")

1. The redirect occurs, but the session variable does not clear.

2. A related issue that ****worries me greatly**** is that once
redirected to the logon page, selecting the browser's back button,
redirects to the web form on which the user has entered data!

This latter page has code in the onload event that looks for the
session variable assignment, and if it doesn't find it, it is supposed
to redirect the user to the logon page...however, since I didn't suceed
in clearing the variable using the session methods, above, this does
not work...

Can someone educate me?

Thank you.
J.

Nov 19 '05 #2
I use code like this:
--
Joe Fallon
Access MVP

<JJ****@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
In a "Save and Quit" button on my web app form (aspx), I have the
following code that is supposed to clear a session variable (an user
id) and redirect to a logon page:

Session.Clear()
Session.Abandon()
Response.Redirect("ApplicantLogon.aspx")

1. The redirect occurs, but the session variable does not clear.

2. A related issue that ****worries me greatly**** is that once
redirected to the logon page, selecting the browser's back button,
redirects to the web form on which the user has entered data!

This latter page has code in the onload event that looks for the
session variable assignment, and if it doesn't find it, it is supposed
to redirect the user to the logon page...however, since I didn't suceed
in clearing the variable using the session methods, above, this does
not work...

Can someone educate me?

Thank you.
J.

Nov 19 '05 #3
I use code like this:

HttpContext.Current.Session.Clear()
System.Web.Security.FormsAuthentication.SignOut()
HttpContext.Current.User = Nothing
Response.Redirect("~/Login.aspx", True)

--
Joe Fallon


<JJ****@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
In a "Save and Quit" button on my web app form (aspx), I have the
following code that is supposed to clear a session variable (an user
id) and redirect to a logon page:

Session.Clear()
Session.Abandon()
Response.Redirect("ApplicantLogon.aspx")

1. The redirect occurs, but the session variable does not clear.

2. A related issue that ****worries me greatly**** is that once
redirected to the logon page, selecting the browser's back button,
redirects to the web form on which the user has entered data!

This latter page has code in the onload event that looks for the
session variable assignment, and if it doesn't find it, it is supposed
to redirect the user to the logon page...however, since I didn't suceed
in clearing the variable using the session methods, above, this does
not work...

Can someone educate me?

Thank you.
J.

Nov 19 '05 #4
Exactly. Thank you. I stumbled onto this, recalling from my previous
life as an asp programmer...except, I am using a page directive to set
cache to none. I am using vb.net, and therefore can set this
programmatically in page load. Don't know that there is any difference
between setting cache as a page directive or programmatically in page
load?

Nov 19 '05 #5
Thank you - that is very specific and I am not familiar with lines 2
and 3, but I will investigate.

Nov 19 '05 #6
Update: session variable does clear: because I'm not controlling cache
output, I didn't realize this...see following...

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
6
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter,...
1
by: Tyros | last post by:
I'm new to C# and I'm dynamically creating a table control that contains a text control inside one of the cells. I load the values of each text field with an SQL call. The form is simple and I'm...
0
by: PD | last post by:
I am trying to stream out a PDF file via the response object and when I execute the code it always brings up the first document that I pulled up.Even when I step through the code, I can see the new...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
4
by: Amy | last post by:
I'm having a problem with clearing my session variables. I'm using session variables to pass data from a web form to a pdf generator. The problem comes in when a user goes back to the original...
7
by: Kermit Piper | last post by:
Hello, How can you clear session variables when a reset button is pressed? I thought I might be able to do something like: <% If request.form("Reset") = "Reset" then Session("variable") =...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
26
by: BillE | last post by:
Some ASP.NET applications use Session Variables extensively to maintain state. These should be re-written to use viewstate, hidden fields, querystring, etc. instead. This is because if a user...
6
by: =?Utf-8?B?R2Vv?= | last post by:
Hi, I use lots of sessions. I want to clear the unwanted sessions when I leave a page. I cant use ViewState as it will slow down the pages. Could some one help me on this?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.