2017-04-14 29 views

回答

1

有不同的方法来实现你想要的。假设you're与ASP.NET MVC工作4+你可以使用:

Application_BeginRequest() 

您可以在Global.asax.cs

注册此事件例如,你可以访问你的要求就像这样:

protected void Application_BeginRequest(object sender, EventArgs e) 
    { 
     //Perform actions on HttpContext.Current.Request 
    } 

你可以在这个事件here (DotNetPerls Example)找到一个很好的概述。

另一种可能的解决方案是GlobalFilter。这已经回答了很多次,你可以得到更多的信息Here (Stack Overflow Answer)

这取决于你的用例你喜欢哪个版本。