Context
I’m in a controller.
I use the namespace System.Web :
using System.Web;
When I call HttpContext.Current, VS alerts me that Current isn’t defined in HttpContextBase :
HttpContext.Current.Session["currentUser"];
If I indicate System.Web before HttpContext.Current, it works :
System.Web.HttpContext.Current.Session["currentUser"];
Question
Why should I indicate System.Web before HttpContext.Current?
This is because you are in the context of a controller. A controller has a property called
HttpContextof the typeHttpContextBase. The instance of this property is a wrapper around the currentHttpContext, this means you don’t have to callHttpContext.Currentas this already is available in the controller using the property.You could do it like this instead (as long as you are in a controller):