473,748 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warning - AVOID SESSION VARIABLES

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 opens a new IE window with Ctrl-N or
File-New-Window, BOTH WINDOWS SHARE THE SAME SESSION VARIABLES. This cannot
be prevented.

This means that if you change the value of a session variable in the second
window, it is also changed in the first window.

Session variables should only be used if this behavior is recognized and
compensated for.

I inherited a VB6 web class application which uses session variables
extensively. Users told me that sometimes orders were being added for the
wrong customer. I found that this occured when they opened a second browser
using Ctrl-N, changed the customer in the new window, and then returned to
the first window to add an order. They didn't realize that the customer
displayed in the first window was no longer consistent with the customer ID
stored in the shared CustomerID session variable.


Oct 19 '06 #1
26 3613
This is a long known issue. If a new browser is pulled from the old browser,
both have the same name, which means they share session. You can prevent
this by checking user input and ensuring you are dealing with the same
record. It is more a practices problem than a session problem.

On the other hand, I agree that you should keep page specific stuff in the
page. ViewState is a good option here.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************** *************** *************** ****
Think outside of the box!
*************** *************** *************** ****
"BillE" <be****@datamti .comwrote in message
news:Oo******** ******@TK2MSFTN GP02.phx.gbl...
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 opens a new IE window with Ctrl-N or
File-New-Window, BOTH WINDOWS SHARE THE SAME SESSION VARIABLES. This
cannot be prevented.

This means that if you change the value of a session variable in the
second window, it is also changed in the first window.

Session variables should only be used if this behavior is recognized and
compensated for.

I inherited a VB6 web class application which uses session variables
extensively. Users told me that sometimes orders were being added for the
wrong customer. I found that this occured when they opened a second
browser using Ctrl-N, changed the customer in the new window, and then
returned to the first window to add an order. They didn't realize that
the customer displayed in the first window was no longer consistent with
the customer ID stored in the shared CustomerID session variable.


Oct 19 '06 #2
"Cowboy (Gregory A. Beamer)" <No************ @comcast.netNoS pamMwrote in
message news:ei******** ********@TK2MSF TNGP05.phx.gbl. ..
On the other hand, I agree that you should keep page specific stuff in the
page. ViewState is a good option here.
That's just common sense, surely...?
Oct 19 '06 #3
I think that the only way to ensure you are dealing with the same record is
to avoid session variables.

For example, if you are using Master pages, as far as I can tell, this means
that a customer ID must be passed by query string for GET requests, and by
hidden fields for POST requests when a new child page is being called.

Is this an accurate statement?

Thanks
-Bill
"Cowboy (Gregory A. Beamer)" <No************ @comcast.netNoS pamMwrote in
message news:ei******** ********@TK2MSF TNGP05.phx.gbl. ..
This is a long known issue. If a new browser is pulled from the old
browser, both have the same name, which means they share session. You can
prevent this by checking user input and ensuring you are dealing with the
same record. It is more a practices problem than a session problem.

On the other hand, I agree that you should keep page specific stuff in the
page. ViewState is a good option here.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************** *************** *************** ****
Think outside of the box!
*************** *************** *************** ****
"BillE" <be****@datamti .comwrote in message
news:Oo******** ******@TK2MSFTN GP02.phx.gbl...
>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 opens a new IE window with Ctrl-N or
File-New-Window, BOTH WINDOWS SHARE THE SAME SESSION VARIABLES. This
cannot be prevented.

This means that if you change the value of a session variable in the
second window, it is also changed in the first window.

Session variables should only be used if this behavior is recognized and
compensated for.

I inherited a VB6 web class application which uses session variables
extensively. Users told me that sometimes orders were being added for
the wrong customer. I found that this occured when they opened a second
browser using Ctrl-N, changed the customer in the new window, and then
returned to the first window to add an order. They didn't realize that
the customer displayed in the first window was no longer consistent with
the customer ID stored in the shared CustomerID session variable.



Oct 19 '06 #4
"BillE" <be****@datamti .comwrote in message
news:%2******** **********@TK2M SFTNGP03.phx.gb l...
For example, if you are using Master pages, as far as I can tell, this
means that a customer ID must be passed by query string for GET requests,
and by hidden fields for POST requests when a new child page is being
called.

Is this an accurate statement?
Not im my experience - I use ViewState all the time within ContentPages...
Oct 19 '06 #5
Do your content pages initially receive parameters from query strings or
hidden fields?

"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:er******** ******@TK2MSFTN GP04.phx.gbl...
"BillE" <be****@datamti .comwrote in message
news:%2******** **********@TK2M SFTNGP03.phx.gb l...
>For example, if you are using Master pages, as far as I can tell, this
means that a customer ID must be passed by query string for GET requests,
and by hidden fields for POST requests when a new child page is being
called.

Is this an accurate statement?

Not im my experience - I use ViewState all the time within ContentPages...

Oct 19 '06 #6
"BillE" <be****@datamti .comwrote in message
news:ul******** ******@TK2MSFTN GP04.phx.gbl...
Do your content pages initially receive parameters from query strings or
hidden fields?
Neither - they most often receive them from a Session variable which is read
and destroyed on Page_Load, surrounded by if (!IsPostBack). If the user
tries to open the page directly either by typing the URL into the address
bar directly or clicking File, New, that Session variable won't be there, so
the process will not continue. Instead, the user will be redirected to an
error page telling them not to do what they tried to do...
Oct 19 '06 #7
Good solution. Thanks!

"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:e2******** *****@TK2MSFTNG P05.phx.gbl...
"BillE" <be****@datamti .comwrote in message
news:ul******** ******@TK2MSFTN GP04.phx.gbl...
>Do your content pages initially receive parameters from query strings or
hidden fields?

Neither - they most often receive them from a Session variable which is
read and destroyed on Page_Load, surrounded by if (!IsPostBack). If the
user tries to open the page directly either by typing the URL into the
address bar directly or clicking File, New, that Session variable won't be
there, so the process will not continue. Instead, the user will be
redirected to an error page telling them not to do what they tried to
do...

Oct 19 '06 #8
Your concern is valid, but this isn't really a problem with session
variables. It's more a question of where you should store different kind
of state.

Session variables are suitable for values that remain the same
throughout the session, like the id of the logged in user. The id of the
customer that you are currently viewing is something that should follow
the page rather than the session.

If you would store session specific data in an application variable,
that would of course be a problem if there ever is more than one session
active at the same time. In the same way, if you store page specific
data in a session variable, there is a problem if one user has more than
one page open at the same time.
BillE wrote:
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 opens a new IE window with Ctrl-N or
File-New-Window, BOTH WINDOWS SHARE THE SAME SESSION VARIABLES. This cannot
be prevented.

This means that if you change the value of a session variable in the second
window, it is also changed in the first window.

Session variables should only be used if this behavior is recognized and
compensated for.

I inherited a VB6 web class application which uses session variables
extensively. Users told me that sometimes orders were being added for the
wrong customer. I found that this occured when they opened a second browser
using Ctrl-N, changed the customer in the new window, and then returned to
the first window to add an order. They didn't realize that the customer
displayed in the first window was no longer consistent with the customer ID
stored in the shared CustomerID session variable.

Oct 19 '06 #9
Well put.

Unfortunately, I suspect there are many developers who use the convenience
of session variables to persist values (like Customer ID) without realizing
that a user will eventually compromise the application with a simple action
like Ctrl-N.

The only time I see this risk mentioned is in posts in newsgroups and forums
from distressed and perplexed developers!

Thanks
Bill
"Göran Andersson" <gu***@guffa.co mwrote in message
news:Of******** ********@TK2MSF TNGP03.phx.gbl. ..
Your concern is valid, but this isn't really a problem with session
variables. It's more a question of where you should store different kind
of state.

Session variables are suitable for values that remain the same throughout
the session, like the id of the logged in user. The id of the customer
that you are currently viewing is something that should follow the page
rather than the session.

If you would store session specific data in an application variable, that
would of course be a problem if there ever is more than one session active
at the same time. In the same way, if you store page specific data in a
session variable, there is a problem if one user has more than one page
open at the same time.
BillE wrote:
>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 opens a new IE window with Ctrl-N or
File-New-Window, BOTH WINDOWS SHARE THE SAME SESSION VARIABLES. This
cannot be prevented.

This means that if you change the value of a session variable in the
second window, it is also changed in the first window.

Session variables should only be used if this behavior is recognized and
compensated for.

I inherited a VB6 web class application which uses session variables
extensively. Users told me that sometimes orders were being added for
the wrong customer. I found that this occured when they opened a second
browser using Ctrl-N, changed the customer in the new window, and then
returned to the first window to add an order. They didn't realize that
the customer displayed in the first window was no longer consistent with
the customer ID stored in the shared CustomerID session variable.


Oct 19 '06 #10

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

Similar topics

4
1984
by: Jake Lloyd | last post by:
In "A Note on Security In PHP" (partly in reference to a security flaw that exists or recently did exist in phpBB) at http://nl3.php.net/security-note.php The PHP Group makes this claim: "Every remote exploit can be avoided with very careful input validation." This is very reassuring, if it is true, and it gives much to be said in favor of implementing PHP in applications that accept remote user input. But is it true? One rarely sees an...
0
1900
by: patel | last post by:
Hello, I get this warning with my PHP code sometimes. It will come up, and then after reloading the page once or twice, it will go away. Any ideas? The code is below: Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality...
10
3512
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much more time I have on a session? If I do a refresh, does reset the session clock? Do you have have to go to another page to reset the session timeout or will a postback also do it? This is important as we have a few pages that a user
19
7926
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
10
2669
by: Atul Shukla | last post by:
Hi, How can I avoid application timeout? Generally a web application time out is 20 minutes, however, we can define this timeout in web.config to any number of minutes. After giving 500 minutes of time out which is about little more than 8 hours, the page expires in less than 2 hours. I am confused here how to avoid this timeout problem. I just dont want my page to be expired, should work similar to windows application. Possible?
8
2397
by: mcserret | last post by:
I know this is a recurring problem that has been addressed here before, but even after reading all that has gone before, I am still stumped. I have a form that is designed to send data to a PHP page where is is to be validated then read into a MySQL table. Once that is done, the form is to send the user either back to the originating page, or to a logout page. I have several versions of this setup on my site that work well, so
11
2135
by: Jeff | last post by:
I turned on errors in php: ini_set('display_errors','1'); And I got a slew of notices and a couple of warnings. The notices are mostly missing indexes from doing things like this: $some_var = $_REQUEST;
1
2846
by: anithaapr05 | last post by:
I have got the warning in event viewer when i wrote the code in global.asax session_end(). When the user sessions time out, the Session_End event fires successfully.But i got the waring in event viewer. My Waring is Event code: 3005 Event message: An unhandled exception has occurred. Event time: 8/14/2009 3:04:16 PM
1
3043
by: anithaapr05 | last post by:
After the session end i try to write the session value.In this, it write the session value after the session end, but i got the warning in application event. My asp code: void Session_End(object sender, EventArgs e) { // Code that runs when a session ends. // Note: The Session_End event is raised only when the sessionstate mode // is set to InProc in the Web.config file. If session mode is set to...
0
8983
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8822
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9359
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.