Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Is access to the Session thread-safe?

Reply
Thread Tools

Is access to the Session thread-safe?

 
 
Chris Newby
Guest
Posts: n/a
 
      03-28-2005
When accessing, for example, an object stored in the session such as:

Session[ "MyObject" ].MyProperty = "Some Value";

Is access to MyObject thread-safe?


 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      03-28-2005
Hi Chris:

Here are some details:

ASP.NET does manage access to session state with a ReaderWriterLock.
The default is to take a writer lock, which serializes requests coming
in on the same session (using EnableSessionState="ReadOnly" takes a
reader lock and does allow concurrent request processing on a
session).

In this example, you are not really modifying session state, but
modifying an object through a reference stored in session state. If
anyone else has a reference to the same object the code is only thread
safe if MyObject is thread safe.

Know what I mean?

--
Scott
http://www.OdeToCode.com/blogs/scott/


On Sun, 27 Mar 2005 19:59:26 -0500, "Chris Newby"
<(E-Mail Removed)> wrote:

> When accessing, for example, an object stored in the session such as:
>
>Session[ "MyObject" ].MyProperty = "Some Value";
>
>Is access to MyObject thread-safe?
>


 
Reply With Quote
 
 
 
 
Chris Newby
Guest
Posts: n/a
 
      03-28-2005
Yeah, makes perfect sense.

Could you possibly elaborate a little more on exactly when ASP.NET creates
and releases the ReaderWriter Lock?


"Scott Allen" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hi Chris:
>
> Here are some details:
>
> ASP.NET does manage access to session state with a ReaderWriterLock.
> The default is to take a writer lock, which serializes requests coming
> in on the same session (using EnableSessionState="ReadOnly" takes a
> reader lock and does allow concurrent request processing on a
> session).
>
> In this example, you are not really modifying session state, but
> modifying an object through a reference stored in session state. If
> anyone else has a reference to the same object the code is only thread
> safe if MyObject is thread safe.
>
> Know what I mean?
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
>
> On Sun, 27 Mar 2005 19:59:26 -0500, "Chris Newby"
> <(E-Mail Removed)> wrote:
>
> > When accessing, for example, an object stored in the session such as:
> >
> >Session[ "MyObject" ].MyProperty = "Some Value";
> >
> >Is access to MyObject thread-safe?
> >

>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      03-28-2005
When the SessionStateModule catches the AcquireRequestState event
during request processing. This happens before control reaches the
ASPX page handler.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 27 Mar 2005 21:15:12 -0500, "Chris Newby"
<(E-Mail Removed)> wrote:

>Yeah, makes perfect sense.
>
>Could you possibly elaborate a little more on exactly when ASP.NET creates
>and releases the ReaderWriter Lock?
>
>


 
Reply With Quote
 
Chris Newby
Guest
Posts: n/a
 
      03-28-2005
Thanks Scott, very helpful//

"Scott Allen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> When the SessionStateModule catches the AcquireRequestState event
> during request processing. This happens before control reaches the
> ASPX page handler.
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Sun, 27 Mar 2005 21:15:12 -0500, "Chris Newby"
> <(E-Mail Removed)> wrote:
>
> >Yeah, makes perfect sense.
> >
> >Could you possibly elaborate a little more on exactly when ASP.NET

creates
> >and releases the ReaderWriter Lock?
> >
> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very annoying error: Access to the path is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity Jay ASP .Net 2 08-20-2007 07:38 PM
Session Timeout problems-web.confg session state and IIS session s =?Utf-8?B?Um9iSEs=?= ASP .Net 4 04-11-2007 04:52 PM
How do I let people access the internet via an access point but not allow them access to my network yar Wireless Networking 4 09-21-2004 03:48 AM
Session State - What does it take to establish one single ASP.NET session per "browser session" Jeff Smythe ASP .Net 3 01-02-2004 04:10 AM
How can I "know" the difference between a session timed out and a session that did session.abort? Jazzis ASP General 2 09-23-2003 07:16 AM



Advertisments