473,738 Members | 11,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpContext.Cur rent 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.Cur rent 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.Cur rent 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 1939
> Now my question is how can a static property point you to the right
request/response/session? How can this static HttpContext.Cur rent 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.Cur rent 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.Cur rent 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 ThreadStaticAtt ribute. 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.c om> 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.Cur rent 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.Cur rent 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
3217
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) Command.Parameters("MyID").Value = Guid.NewGuid.ToString System.Web.HttpContext.Current.Session("ID") = Command
4
7944
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 HttpContext.Current to get Session Variable value. Here my code fails. Thread on which the process is running does not have HTTPContext.Current object. How can I pass-on HTTPContext.Current info to thread. I used WindowsImpersonationContext for...
15
2532
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 GenericPrincipal object that I attached to Context.User. My question is this: Can I create a new class, ExtendedPrincipal for instance, and simply inherit System.Security.Principal and store all of the information currently stored in Session...
3
1947
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 class also includes a class that is used for logging. This logging class uses HttpContext.Current.Handler to get the instance of the page. In this way, it can get the PageTitle property.
3
2973
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 HttpModule to initialize an instance of a custom class, and have this class exposed directly through the HttpRequest for the current user through a property I add to the HttpRequest object. For example, I'd like my developers to be able to use this...
0
2186
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 access any other property property of this class from a regular aspx page, but not from inside the class itself. This is the piece of the code that I am trying to get to work which can also be located at the bottom of the page, but so far just...
4
10176
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 page and try to access that cookie. However, because I am using HttpContext.Current.User.Identity.Name to get the user id to know what that cookie name even is, I am having problems because apparently after 30 minutes...
8
2543
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 copies. to do that, the BAL needs to be aware of the user's HttpContext. question: how expensive is it for each BAL method to instantiate the current context, like so:
13
53334
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 set the value in the login form, however when FormsAuthentication.RedirectFromLoginPage() redirects the call to my Default.aspx the HttpContext.Current.User has a completely different value. Within the ValidateUser() I'm constructing my custom...
0
8969
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
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
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
6053
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
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.