model-view-controllerasp.net-web-apiaction-filteractionfilterattributefilterattribute

Change Action to be executed on ASP.NET WebAPI with ActionFilterAttribute


My goal is to develop a Custom FilterAttribute, there i can apply to an action on ASP.NET Web API, where one of two thing should happens, but the resul must be the same:

Expected result: if some condition is verified, the action execution should be cancelled or redirected and a different object should be returned;

on a filterattribute to mvc i just have to change the actionname when im overriding a specific method.

does any one have ideas how to do the same on a webapi filterattribute?

SOLUTION:

if (true)
{
    IHttpRouteData x = request.Properties["MS_HttpRouteData"] as IHttpRouteData;
    x.Values["action"] = "IsUnavailableBecause";
}

Solution

  • I'm not sure I understand what you are trying to do. Can you give an example?

    Using message handlers would allow you to change the action route parameter before action selection has occurred.