Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Variables in multiple sessions (http://www.velocityreviews.com/forums/t700065-variables-in-multiple-sessions.html)

Jacques Oberto 10-01-2009 03:17 PM

Variables in multiple sessions
 
Hi All,

[newbie question]
My ASP.NET page does some processing using
data from user input. In the case of multiple
simultanous sessions, will the internal variables
of my application remain isolated between sessions
or is there danger of data mixing?
Thanks,

Jacques



Scott M. 10-01-2009 03:32 PM

Re: Variables in multiple sessions
 
Each page request, results in a specific instance of a page class being
created. As with any instance of an object, it's data is isolated from data
in other instances (even if it is another instance of the same kind of
object).

The only time you'll have to worry about one user accessing data that
another use may also be using is when you have a page access a "shared"
memory space, such as application variables or shared data, such as a
database.

-Scott

"Jacques Oberto" <jo@nospam.com> wrote in message
news:ea6jTpqQKHA.5032@TK2MSFTNGP05.phx.gbl...
> Hi All,
>
> [newbie question]
> My ASP.NET page does some processing using
> data from user input. In the case of multiple
> simultanous sessions, will the internal variables
> of my application remain isolated between sessions
> or is there danger of data mixing?
> Thanks,
>
> Jacques
>
>




Alexey Smirnov 10-01-2009 03:35 PM

Re: Variables in multiple sessions
 
On Oct 1, 5:17*pm, "Jacques Oberto" <j...@nospam.com> wrote:
> Hi All,
>
> [newbie question]
> My ASP.NET page does some processing using
> data from user input. In the case of multiple
> simultanous sessions, will the internal variables
> of my application remain isolated between sessions
> or is there danger of data mixing?
> Thanks,
>
> Jacques


Yes, each active session is identified and tracked using a 120-bit
SessionID, generated using an algorithm that guarantees uniqueness.
The SessionID strings are communicated across client-server requests
either by means of an HTTP cookie or a modified URL with the SessionID
string embedded, depending on how you configure the application
settings.

More: http://msdn.microsoft.com/en-us/library/87069683.aspx

Scott M. 10-01-2009 04:18 PM

Re: Variables in multiple sessions
 

"Alexey Smirnov" <alexey.smirnov@gmail.com> wrote in message
news:f252d131-f51c-4b31-b9d2-5d8a6f552abf@y36g2000yqh.googlegroups.com...
On Oct 1, 5:17 pm, "Jacques Oberto" <j...@nospam.com> wrote:
> Hi All,
>
> [newbie question]
> My ASP.NET page does some processing using
> data from user input. In the case of multiple
> simultanous sessions, will the internal variables
> of my application remain isolated between sessions
> or is there danger of data mixing?
> Thanks,
>
> Jacques


>Yes, each active session is identified and tracked using a 120-bit
>SessionID, generated using an algorithm that guarantees uniqueness.
>The SessionID strings are communicated across client-server requests
>either by means of an HTTP cookie or a modified URL with the SessionID
>string embedded, depending on how you configure the application
>settings.


>More: http://msdn.microsoft.com/en-us/library/87069683.aspx


I don't believe the OP is asking about session object per se, I believe he's
just asking about the VB or C# code variables that are part of the page's
code, which are contained within each instance of the page.

-Scott



Jacques Oberto 10-01-2009 04:23 PM

Re: Variables in multiple sessions
 

"Scott M." a écrit
> Each page request, results in a specific instance of a page class being
> created. As with any instance of an object, it's data is isolated from
> data in other instances (even if it is another instance of the same kind
> of object).
>
> The only time you'll have to worry about one user accessing data that
> another use may also be using is when you have a page access a "shared"
> memory space, such as application variables or shared data, such as a
> database.
>
> -Scott
>


Hi Scott,

No offense meant but your reply is confusing me. If the page data is
isolated
from data of other page instances, are the application variables isolated as
well or not?
Thanks,

Jacques



Patrice 10-01-2009 04:45 PM

Re: Variables in multiple sessions
 
What are those "internal variables" ?

Static (or VB Shared members) and what you stored in application variables
or in the cache object is shared accross the application (and ASP.NET is a
single app used by multiple users so all users will use the same value). In
other cases, it (such as for session variable) it should be fine.

If you have a problem, tell us what you see, it will be easier to diagnose
than talking about generalities...

--
Patrice


"Jacques Oberto" <jo@nospam.com> a écrit dans le message de groupe de
discussion : ea6jTpqQKHA.5032@TK2MSFTNGP05.phx.gbl...
> Hi All,
>
> [newbie question]
> My ASP.NET page does some processing using
> data from user input. In the case of multiple
> simultanous sessions, will the internal variables
> of my application remain isolated between sessions
> or is there danger of data mixing?
> Thanks,
>
> Jacques
>
>
>



Scott M. 10-01-2009 05:24 PM

Re: Variables in multiple sessions
 

"Jacques Oberto" <jo@nospam.com> wrote in message
news:eB81COrQKHA.1232@TK2MSFTNGP05.phx.gbl...
>
> "Scott M." a écrit
>> Each page request, results in a specific instance of a page class being
>> created. As with any instance of an object, it's data is isolated from
>> data in other instances (even if it is another instance of the same kind
>> of object).
>>
>> The only time you'll have to worry about one user accessing data that
>> another use may also be using is when you have a page access a "shared"
>> memory space, such as application variables or shared data, such as a
>> database.
>>
>> -Scott
>>

>
> Hi Scott,
>
> No offense meant but your reply is confusing me. If the page data is
> isolated
> from data of other page instances, are the application variables isolated
> as
> well or not?
> Thanks,
>
> Jacques
>

Well, I think you need to clarify what type of "variables" you are referring
to. In your original post, you did not mention anything about "application"
variables, which are different from "session" variables, which are different
from the variables you create within your C# or VB .NET code to process the
page.

Application variables are just that, variables that hold data that is
specfic to the application and not any particular user. A hit count is a
good example of data stored at the applicaiton level. It doesn't matter
which user is asking for it, there is only one number that represents the
current hit count and that data needs to be shared across all user sessions.
Applicaiton variables look like this: Application("HitCount") = 1000.

Session variables are also what their name suggests. They are variables that
hold data that is specific to a particular user's session and is held in
memory for the duration of the session. Session variables are used when data
from one request/response cycle needs to be carried into the same visitors
next request/response cycle that is part of the same server session.
Session variables look like this: Session("UserName") = txtUser.Text.

Regular page variables (which is what I thought you were asking about and
what my reply is based on) are the simple variables you create within the
code of your page such as:

Public Class thePage
Inherits System.Web.UI.Page

Dim x As DateTime

Sub Page_Load()
x = DateTime.Now
End Sub

End Class

In this case "x" is a page level variable that holds data specific to this
particular "instance" of the page class and would hold data that is isolated
from other instances of the same page class. If I requested the page and
then you requested the page, the server would create two different instances
of "thePage" class and each instance would have different data in its x
variable that cannot be accessed by the other.

-Scott



Jacques Oberto 10-01-2009 05:43 PM

Re: Variables in multiple sessions
 

"Scott M." a écrit

>
> Public Class thePage
> Inherits System.Web.UI.Page
>
> Dim x As DateTime
>
> Sub Page_Load()
> x = DateTime.Now
> End Sub
>
> End Class
>
> In this case "x" is a page level variable that holds data specific to this
> particular "instance" of the page class and would hold data that is
> isolated from other instances of the same page class. If I requested the
> page and then you requested the page, the server would create two
> different instances of "thePage" class and each instance would have
> different data in its x variable that cannot be accessed by the other.
>


Hi Scott,

As I mentioned in my OP, it's the "application variables" I'm interested in.
Your example above makes everything crystal clear.
Thank you for your help.

Jacques


Jacques Oberto 10-01-2009 05:51 PM

Re: Variables in multiple sessions
 

"Patrice" a écrit dans
> What are those "internal variables" ?
>
> Static (or VB Shared members) and what you stored in application variables
> or in the cache object is shared accross the application (and ASP.NET is a
> single app used by multiple users so all users will use the same value).
> In other cases, it (such as for session variable) it should be fine.
>
> If you have a problem, tell us what you see, it will be easier to diagnose
> than talking about generalities...



Hi Patrice,

What you are saying seems to differ from the VB example + explanation given
by Scott M in this same thread. It looks like I am not the only one to have
problems with this...

Jacques


Gregory A. Beamer 10-01-2009 05:59 PM

Re: Variables in multiple sessions
 
"Jacques Oberto" <jo@nospam.com> wrote in news:ea6jTpqQKHA.5032
@TK2MSFTNGP05.phx.gbl:

> Hi All,
>
> [newbie question]
> My ASP.NET page does some processing using
> data from user input. In the case of multiple
> simultanous sessions, will the internal variables
> of my application remain isolated between sessions
> or is there danger of data mixing?


If you have attached the data to a session, then they cannot cross
contaminate via the session variables.

Except, if you have a piece of state (Property/Field) marked as static
(C#) or Shared (VB), as those are part of the class and not part of the
object created from the class (ie, they are shared amongst all
instances).

In other words:

public class MyClass
{
public static MyVariable { get; set; }
}

will shared across all instances, even if you have the following:

Session["MyClass"] = instanceOfMyClass;

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************


All times are GMT. The time now is 12:57 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.