I can't access to HttpContext.Current on my project MVC4 with C#4.5
I've added my reference to System.Web in my project and added the using instruction on my controller page...
But I can access currentHandler only...
var context = HttpContext.CurrentHandler; //Current Is HttpContext.Current deprecated on C#4.5 ?
I've looked this help page : http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx
Instead of using HttpContext. Current , use the HttpContext provided as a property on the Page or Controller , or even better, you can simply use the Session property.
HTTP context accessor. Finally, you can use the IHttpContextAccessor helper service to get the HTTP context in any class that is managed by the ASP.NET Core dependency injection system. This is useful when you have a common service that is used by your controllers.
Current property, instead it is available in the HttpContext class in ASP.Net Core applications. Session can be enabled using the Configure method. Inside this method, you will have to call the UseSession method of the app object. Note: It is mandatory to call the UseSession method before the UseMvc method.
Have you included the System.Web assembly in the application?
using System.Web; If not, try specifying the System.Web namespace, for example:
System.Web.HttpContext.Current
This is because you are referring to property of controller named HttpContext. To access the current context use full class name:
System.Web.HttpContext.Current However this is highly not recommended to access context like this in ASP.NET MVC, so yes, you can think of System.Web.HttpContext.Current as being deprecated inside ASP.NET MVC. The correct way to access current context is
this.ControllerContext.HttpContext or if you are inside a Controller, just use member
this.HttpContext
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With