How to pass ControllerContext to Attribute
-
21-12-2019 - |
Question
I would like to use information from the ControllerContext or ActionContext from inside the Attribute\Filter constructor. How can i do so? Tried to pass the ControllerContext as a parameter to the attribute from the action but with no success.
Solution
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var controllerContext = filterContext.Controller.ControllerContext;
on action executing. You cannot have the context on construction
OTHER TIPS
[HttpGet]
public ActionResult VideoStream(int id = 0)
{
}
public override void ExecuteResult(ControllerContext context)
{
string routedata = context.RequestContext.RouteData.Values["id"].ToString();
//The File Path
var videoFilePath = HostingEnvironment.MapPath("~/CombineFile/Tanvir.mp4");
//The header information
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow