设为首页 加入收藏

TOP

.NET MVC5简介(五)管道处理模型IHttpModule(一)
2019-09-25 11:18:20 】 浏览:159
Tags:.NET MVC5 简介 管道 处理 模型 IHttpModule

https://www.cnblogs.com/JimmyZhang/archive/2007/09/04/880967.html

IHttpModule

HTTPRuntime(运行时)。在一个控制台程序中,程序的入口是Program中的Main方法。那么,一个网站的入口在哪里呢?在最开始的ashx中,有个ProcessRequest方法,后来在WebForm中,在后台是一个不分类,继承自Page类,在Page_Load方法中去写代码。其实Page类型也有一个ProcessRequest的虚方法。

 

 

 都是这个ProcessRequest方法来处理请求的。在MVC中也是如此。在MVC中,任何一个Http请求,一定有一个IHttpHandler来处理,在这个接口中,定义了一个ProcessRequest方法。HttpApplication继承自IHttpHandler接口。任何一个Http请求就是一个HttpApplication对象来处理的,然后处理过程固定包含权限认证、缓存处理、Session处理、Cookie出库、生成html、输出客户端,与此同时,千千万万的开发者,又有各种各样的扩展诉求,任何一个环节都有可能扩展,如果是我们来设计,该怎么设计?

其实在MVC框架里面,用到的是观察者模式:

在HttpApplication类型,有这些事件:

 //
        // 摘要:
        //     Occurs just before ASP.NET sends HTTP headers to the client.
        public event EventHandler PreSendRequestHeaders;
 //
        // 摘要:
        //     Occurs when the handler is selected to respond to the request.
        public event EventHandler MapRequestHandler;
 //
        // 摘要:
        //     Occurs when the application is disposed.
        public event EventHandler Disposed;
 //
        // 摘要:
        //     Occurs as the first event in the HTTP pipeline chain of execution when ASP.NET
        //     responds to a request.
        public event EventHandler BeginRequest;
 //
        // 摘要:
        //     Occurs when a security module has established the identity of the user.
        public event EventHandler AuthenticateRequest;
 //
        // 摘要:
        //     Occurs when a security module has established the identity of the user.
        public event EventHandler PostAuthenticateRequest;
 //
        // 摘要:
        //     Occurs when a security module has verified user authorization.
        public event EventHandler AuthorizeRequest;
 //
        // 摘要:
        //     Occurs when the user for the current request has been authorized.
        public event EventHandler PostAuthorizeRequest;
 //
        // 摘要:
        //     Occurs when ASP.NET finishes an authorization event to let the caching modules
        //     serve requests from the cache, bypassing execution of the event handler (for
        //     example, a page or an XML Web service).
        public event EventHandler ResolveRequestCache;
 //
        // 摘要:
        //     Occurs when ASP.NET bypasses execution of the current event handler and allows
        //     a caching module to serve a request from the cache.
        public event EventHandler PostResolveRequestCache;
 //
        // 摘要:
        //     Occurs just before ASP.NET sends content to the client.
        public event EventHandler PreSendRequestContent;
 //
        // 摘要:
        //     Occurs when ASP.NET has mapped the current request to the appropriate event handler.
        public event EventHandler PostMapRequestHandler;
 //
        // 摘要:
        //     Occurs when ASP.NET has completed processing all the event handlers for the System.Web.HttpApplication.LogRequest
        //     event.
        public event EventHandler PostLogRequest;
 //
        // 摘要:
        //     Occurs when the managed objects that are associated with the request have been
        //     released.
        public event EventHandler RequestCompleted;
 //
        // 摘要:
        //     Occurs when the request state (for example, session state) that is associated
        //     with the current request has been obtained.
        public event EventHandler PostAcquireRequestState;
 //
        // 摘要:
        //     Occurs just before ASP.NET starts executing an event handler (for example, a
        //     page or an XML Web service).
        public event EventHandler PreRequestHandlerExecute;
 //
        // 摘要:
        //     Occurs when the ASP.NET event handler (for example, a page or an XML Web service)
        //     finishes execution.
        public event EventHandler PostRequestHandlerExecute;
 //
        // 摘要:
        //     Occurs after ASP.NET finishe
首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇基于Asp.Net Core MVC和AdminLTE.. 下一篇asp.net core系列 73 Exceptionle..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目