Andrey Markov Andrey Markov - 1 year ago 116
C# Question

ActionContext gone in Microsoft.AspNetCore.Mvc.Controller

I cant find ActionContext in Microsoft.AspNetCore.Mvc.Controller

after i changed my Version to AspNetCore 1.0.0-preview1

this is Controller class (after Change):

enter image description here

And from "Microsoft.AspNet.Mvc" before change :

enter image description here

and code from old method before update :

this.Agent = ControllerInfo.Request.Headers["User-Agent"];
this.IP = ControllerInfo.HttpContext.Features.Get<IHttpConnectionFeature>()?.LocalIpAddress?.ToString();
this.RemoteIP = ControllerInfo.HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress.ToString();
this.Refrence = ControllerInfo.ActionContext.RouteData.Values["controller"].ToString() + "/" + ControllerInfo.ActionContext.RouteData.Values["action"].ToString();

Answer Source

I replaced ActionContext with ControllerContext, and it works for me. I don't know if it's an official migration step, though.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download