Do not find HttpContext.Current

6

I'm trying to create a UrlHelper as follows:

UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

I have already made reference to System.Web , as I saw it as a solution in several places.

using System.Web;

The strange thing about 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?)

    
asked by anonymous 01.12.2015 / 19:09

1 answer

5

Do SOen :

To have a reference to HttpContext.Current you need to change the term

HttpContext.Current

by

System.Web.HttpContext.Current

This is because the class Controller defines a property with the name HttpContext , defined as

public HttpContextBase HttpContext { get; }

HttpContext in class Controller returns a HttpContextBase that does not have the Current property.

That's why you need to use the qualified namespace

    
01.12.2015 / 19:15