This is kind of a hard question to formulate. I’m wondering how HttpContext.Current gets assigned a unique instance for every request considering it’s a static object?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Current is not a static variable, its static property, and get property is nothing but a static method which returns the current Context.
ASP.NET stores some information with current thread, you can always get a local thread storage to store information which is kind of static only in the current thread, and which can be accessible by any method in current thread only.
So ASP.NET stores some local information in the thread in which the http context executes the requested application and from anywhere call to Current will fetch the local thread data and get required information.
You can also look at
[ThreadStatic]attribute which does things almost in similar way.Update
From ASP.NET 4.5 and after, Current
HttpContextis passed throughCallContextinstead of[ThreadStatic], so context remains available through out async calls in single logical context instead of current thread as each async call may end up on different threads.