HttpContext in static functions.

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

If I call HttpContext from within a static function will I always be
guaranteed to get the current HttpContext for the request/code that
called the static function? Is there ever a chance that a user might get
another user's request context instead?

Thanks,
Steve
 
No, but you will have to make sure your code is thread safe and can handle
concurrency issues, otherwise it might seem like to context is getting mixed
up, but its more than likely your code. If you really need the static
function then so be it, but to get around the concurrency issue, you should
really use an instance class. Much easier.
 
Paul said:
No, but you will have to make sure your code is thread safe and can handle
concurrency issues, otherwise it might seem like to context is getting mixed
up, but its more than likely your code. If you really need the static
function then so be it, but to get around the concurrency issue, you should
really use an instance class. Much easier.

Sorry for the confusion. Since I asked two questions in my post, I'm not
sure which one the "No" is for. Are you saying that the HttpContext will
be good and proper, and that I just need to make sure that any other
code that I have around it obeys the necessary requirements for working
in a static setting(no globals, locking collections, etc...)?

Thanks,
Steve
 
Steve,

HttpContext.Current will almost always return the current request context.
<g>

The exception is when you work with work threads. HttpContext is bound to
the incoming ASP.NET worker thread and the Context will be available on that
thread. Outside of that you might have to store away an instance of the
context to maintain access to it.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
 
Back
Top