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";
}
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top