ASP.NET MVC 4 intercept all incoming requests

前端 未结 4 968
粉色の甜心
粉色の甜心 2020-11-27 02:50

Is there a way for me to catch all incoming requests to my ASP.NET MVC 4 app and run some code before continuing the request onward to the specified control

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 03:41

    The most correct way would be to create a class that inherits ActionFilterAttribute and override OnActionExecuting method. This can then be registered in the GlobalFilters in Global.asax.cs

    Of course, this will only intercept requests that actually have a route.

提交回复
热议问题