6
I’m trying to create a Urlhelper as follows:
UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
I already made the reference to System.Web
, as I saw as solution in several places.
using System.Web;
The strange thing that is using is gray (Visual Studio 2015) which shows that he is not even using this reference.
The mistake 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?)
you are using which mvc in vs2015? vnext? if it is vnext, you can forget about the system.web.
– Hoppy
the project is mvc 5, Asp.net Aplication. vs2015, vnext? can not say...
– Carol
Try Urlhelper urlHelper = new Urlhelper(System.Web.Httpcontext.Current.Request.Requestcontext);
– PauloHDSousa
vnext is the mvc6.
– Hoppy
It worked! Weird, because it doesn’t work with using?
– Carol
Using is right, the problem is that Httpcontext that you were pulling was from Controller and not SYSTEM.WEB
– PauloHDSousa
you can user the controller’s Httpcontext, just call Httpcontext.Request.Requestcontext (without Current), which works the same way.
– Fernando Mondo