ASP.NET MVC 4拦截所有的请求 [英] ASP.NET MVC 4 intercept all incoming requests

查看:391
本文介绍了ASP.NET MVC 4拦截所有的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让我赶上的所有传入的请求到我的ASP.NET MVC应用程序4及以后继续请求到指定的控制器/动作之前运行一些code?

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 controller/action?

我需要运行一些自定义AUTH code。与现有的服务,并正确地做到这一点,我需要能够拦截来自所有客户端的所有传入的请求仔细检查一些事情与其他服务。

I need to run some custom auth code with existing services, and to do this properly, I'll need to be able intercept all incoming requests from all clients to double check some things with the other service.

推荐答案

最正确的方法是创建一个继承<一类href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.actionfilterattribute.aspx\">ActionFilterAttribute并覆盖 OnActionExecuting 方法。这可以然后在 GlobalFilters 的Global.asax.cs

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.

这篇关于ASP.NET MVC 4拦截所有的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆