【发布时间】:2011-10-23 16:15:32
【问题描述】:
我试图更好地理解 ASP.NET 和 ASP.NET MVC 背后的“plumbing”。我一直在阅读this page,这对我很有帮助。据我所知,到目前为止,每个 ASP.NET 站点都有一个继承自 System.Web.HttpApplication 的类。 HttpApplication 然后有一系列触发 HttpModules 和 HttpHandlers 的事件,例如 BeginRequest、AuthorizeRequest、End Request 等......然后 HttpModules 和 HttpHandlers 读取和写入当前 HttpContext。
ASP.NET 如何知道要使用哪个 HttpApplication 类?我的应用程序在 Global.asax 文件中有典型的 MvcApplication 类。但是我在这个类中看不到任何与 MVC 相关的东西。我也看不到任何将此类分配为“应用程序”的设置。 ASP.NET 是否总是查找名为 Global.asax 的文件来确定要创建的 HttpApplication 类?还是 ASP.NET 只是在我的程序集中查找从 HttpApplication 继承的任何类?
另外,它如何知道要使用哪些模块和处理程序?我上面提到的页面说您通过 web.config 中的设置来指定处理程序和模块。但是我的 ASP.NET MVC 应用程序的 web.config 中没有这些设置?
如果我在其中一个操作方法中设置断点并检查 HttpContext.Current.ApplicationInstance.Modules 我会看到以下内容:
OutputCache
Session
WindowsAuthentication
FormsAuthentication
PassportAuthentication
RoleManager
UrlAuthorization
FileAuthorization
AnonymousIdentification
Profile
ErrorHandlerModule
ServiceModel
UrlRoutingModule-4.0
ScriptModule-4.0
__DynamicModule_System.Web.WebPages.WebPageHttpModuleDefaultAuthentication
这些是在哪里指定的?同样,如果我检查 HttpContext.Current.Handler,我可以看到它设置为 System.Web.Mvc.MvcHandler。
【问题讨论】:
标签: asp.net asp.net-mvc