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

HttpContext in static functions.

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
Nov 18 '05 #1
3 1313
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 Glavich
Microsoft MVP - ASP.NET
"Steve" <ng*****@digitalnothing.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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

Nov 18 '05 #2
Paul Glavich [MVP - ASP.NET] wrote:
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
Nov 18 '05 #3
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/
----------------------------------
Making waves on the Web
"Steve" <ng*****@digitalnothing.com> wrote in message
news:#o**************@TK2MSFTNGP15.phx.gbl...
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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Francois Malgreve | last post by:
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. ...
5
by: coollzh | last post by:
who can tell the detailed difference of: HttpRuntime, Context, HttpContext.Current sometimes, we can use Context Object instead of HttpContext.Current; sometimes, we can user HttpRuntime...
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...
8
by: eric | last post by:
I have a 2.0 asp.net project. In a class contained within a seperate project, I am trying to reference HttpContext.Current.Session but Session is always null. I've tried implementing...
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.