473,378 Members | 1,386 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,378 software developers and data experts.

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 1902
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Claudio Biagioli | last post by:
I start a parallel thread inside a control with the following code: Private Sub StartParallelProc(ByVal Command As SqlClient.SqlCommand) Dim T As New Threading.Thread(AddressOf ParallelProc) ...
4
by: Makarand Keer | last post by:
Hi All I have problem in using Threading. I have ASP.NET application in which I am using multithreading to start a process. Now the object instances which are used in this thread access...
15
by: Jason | last post by:
Currently, I am storing information about the currently logged on user in Session variables that are stored in SQL. However, I am using role-based security, so I am storing custom roles in a...
3
by: Steve Lutz | last post by:
Hello All, I have an ASPX page whose class inherits from a company global base page. The company base page has a property call PageTitle (string) that is assigned by all the pages. The base...
3
by: Steve Franks | last post by:
Is there a way I can extend the HttpContext or one of its subclasses to include a property that exposes a custom class of mine to all ASP.NET pages? More specifically, I'd like to use a...
0
by: Rodusa | last post by:
I am trying to replace cookies with the new "Asp.net 2.0 profiles" in my shopping cart application, but I am having trouble to access profile properties using HttpContext.Current.Profile. I can...
4
by: Doogie | last post by:
Hi, I am using HttpContext.Current.User.Identity.Name to get a user id from a web application. I then use that as part of a name of a cookie I'm writing. 30 minutes later I do a refresh of this...
8
by: SpaceMarine | last post by:
hello, my web app form has many DropDownLists that pull their content from a database. these calls are in a Business Access Layer, when first checks the context's Cache object for existing...
13
by: bproddu | last post by:
Hi, I'm using Forms authentication for my web app. I've a custom Principal class that I would like to set to the HttpContext.Current.User after the Membership.ValidateUser() passes. I'm able to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.