Omtechguy
Omtechguy

Reputation: 3651

How to pass ControllerContext to Attribute

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.

Upvotes: 2

Views: 2608

Answers (2)

Tanavirrul haq
Tanavirrul haq

Reputation: 11

   [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 

    } 

Upvotes: 0

dove
dove

Reputation: 20674

public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
           var controllerContext =  filterContext.Controller.ControllerContext;

on action executing. You cannot have the context on construction

Upvotes: 2

Related Questions