Reputation: 4178
I'm trying to get some info about my users in asp.net mvc application with visual studio 2015.
When i try to to get info from request with
System.Web.HttpContext.Current req = new System.Web.HttpContext.Current();
I get an error Error CS0426 The type name 'Current' does not exist in the type 'HttpContext'
Anyone know how to fix this?
Upvotes: 15
Views: 27347
Reputation: 85
Just add the System.Web
reference to your project and it'll be ok.
using System.Web;
does not generate an error even if the reference does not exist.
Upvotes: 3
Reputation: 10068
If you want to get the current context
System.Web.HttpContext currentContext = System.Web.HttpContext.Current;
If you want to create one (for some reason, like test)
System.Web.HttpContext newContext = new System.Web.HttpContext(
new System.Web.HttpRequest("", "http://example.com", ""),
new System.Web.HttpResponse(new System.IO.StringWriter())
);
Upvotes: 12