Question:
I'm trying to create a UrlHelper like this:
UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
I've already referred to System.Web
, as I've seen it as a solution in several places.
using System.Web;
The strange thing is that this using is gray (Visual Studio 2015) which shows that it is not even using this reference.
The error is:
Error CS1061 'HttpContextBase' does not contain a definition for 'Current' and no extension method 'Current' accepting a first argument of type 'HttpContextBase' could be found (are you missing a using directive or an assembly reference?)
Answer:
To have a reference to HttpContext.Current
you need to change the term
HttpContext.Current
for
System.Web.HttpContext.Current
This is because the Controller
class defines a property named HttpContext
, defined as
public HttpContextBase HttpContext { get; }
HttpContext
in the Controller
class returns an HttpContextBase
that does not have a Current
property.
So you need to use the qualified namespace