如何在 MVC 应用程序中注册全局消息处理程序?
我尝试在我的 Global.asax.cs 中注册它,但是当我访问从 System.Web.Mvc.Controller 继承的所有控制器中的任何端点时,这个处理程序永远不会被调用。
但是,当我访问从 System.Web.Http.ApiController 继承的所有控制器的路由时,它确实会被调用。
这就是我放入 Global.asax.cs 的内容:
protected void Application_Start()
{
//other initializing stuff here
**GlobalConfiguration.Configuration.MessageHandlers.Add(new AuthenticationHandler());**
}