468,290 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

HttpContext.Current Property

hello guys,

I have some helper class in my ASP.NET pplication who basically contains
static methods. I used them as helper methods to do small jobs that I can
use at many places in my code.

As those classes methods are static, they are never associated with any
instance, then not assoicated with any HttpRequest neither.
Nevertheless in some case I ended up myself passing the Session object to my
static methods to be able to get some session related information. But then
I found the sstatic property HttpContext.Current which returns me an
HttpContext object. In which I can find all my objects related to a session,
request and response. Miracle.

Now my question is how can a static property point you to the right
request/response/session? How can this static HttpContext.Current property
point you to the right HttpContext object? Is ASP.NET mono threaded the
Context is attached some how to the thread? Or if it is multithreaded (a
thread per request I would assume) is the context attached to the thread
serving a particular request? I need to understsand the underlying mechanism
to be sure that I won't have any bug later on.

Thank you to give me any information or point me to any doc explaining the
mechanism of that static property.

Best regards,

Francois
Nov 18 '05 #1
2 1668
> Now my question is how can a static property point you to the right
request/response/session? How can this static HttpContext.Current property
point you to the right HttpContext object? Is ASP.NET mono threaded the
Context is attached some how to the thread? Or if it is multithreaded (a
thread per request I would assume) is the context attached to the thread
serving a particular request? I need to understsand the underlying mechanism to be sure that I won't have any bug later on.


It seems you are misinterpreting the Static keyword. Static is not constant,
it just means there is no context available for the HttpContext object
itself when the property's get method is being processed and that you may
therefor invoke it on the HttpContext class as you may on a HttpContext
instance. Static does not mean you will always get the same value, a static
property could return the current time for that matter (like DateTime.Now).

So HttpContext.Current gives you a HttpContext instance which wraps stuff
related to the current page request. This may be a diffenrent instance for
each page request or the same object for each request within the same
session that is being updated by ASP.NET on each request, I don't know. The
Current property's get method just fetches and returns an appropriate
HttpContext for you.
Nov 18 '05 #2
Although I cannot find it officially documented, I'd bet the
HttpContent.Current property pulls data stored in thread local storage
(TLS). TLS gives each thread a location to store thread specific data.
In .NET TLS is setup using the ThreadStaticAttribute. TLS would allow
the ASP.NET runtime to associate a request context with each thread
while remaining multithreded.

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

On Mon, 5 Jan 2004 10:23:19 +0700, "Francois Malgreve" <francois at
bettinghouses.com> wrote:
hello guys,

I have some helper class in my ASP.NET pplication who basically contains
static methods. I used them as helper methods to do small jobs that I can
use at many places in my code.

As those classes methods are static, they are never associated with any
instance, then not assoicated with any HttpRequest neither.
Nevertheless in some case I ended up myself passing the Session object to my
static methods to be able to get some session related information. But then
I found the sstatic property HttpContext.Current which returns me an
HttpContext object. In which I can find all my objects related to a session,
request and response. Miracle.

Now my question is how can a static property point you to the right
request/response/session? How can this static HttpContext.Current property
point you to the right HttpContext object? Is ASP.NET mono threaded the
Context is attached some how to the thread? Or if it is multithreaded (a
thread per request I would assume) is the context attached to the thread
serving a particular request? I need to understsand the underlying mechanism
to be sure that I won't have any bug later on.

Thank you to give me any information or point me to any doc explaining the
mechanism of that static property.

Best regards,

Francois


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Claudio Biagioli | last post: by
4 posts views Thread by Makarand Keer | last post: by
15 posts views Thread by Jason | last post: by
8 posts views Thread by SpaceMarine | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.