c# - During OnActionExecuting for Web API call - How to map to controller/action class from route string to read action attributes -


how can map incoming route string (e.g. products/getproduct) controller/method called (the productscontroller, getproduct method)?

my goal inspect instance of productscontoller find custom attribute put on getproduct method.

i know how inspect class once know which class/method i'm dealing with.

i had considered splitting string, you'd end "products", , "getproducts", can productscontroller, , within that, method called getproducts.

this might work, seems there should better solution. ideas?

you can actual controller instance , attributes on action using:

public class somefilter : actionfilterattribute     {         public override void onactionexecuting(httpactioncontext actioncontext)         {             var controller = actioncontext.controllercontext.controller;             var somefilterattributes = actioncontext.actiondescriptor.getcustomattributes<somefilter>()             var otherattributes = actioncontext.actiondescriptor.getcustomattributes<other>()         }     } 

where other other filter on action.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -