Http请求处理流程 管道流程 MVC扩展HttpModule
HttpApplication 封装了管道处理请求的所有事件
HttpModule 对HttpApplication中事件的扩展
HttpHandler 处理程序 每个请求都要经过Handler处理
HttpContext 容器 保存了请求的所有信息
请求进来 先直接内置的所有管道事件也就是所有的HttpModule 然后执行HttpHandler 这个就是自己对请求进行的操作 自己写的代码
HttpHandler和HttpModule都可以处理http请求 HttpModule的作用类似AOP,是针对某些通用功能(请求拦截、身份认证、检查功能)的,而HttpHandler常用来处理某一类(ashx、aspx、asmx)http请求
EntityFramework 版本
扩展HttpModule
HttpModule是每个请求都会执行到的
1.创建一个类 继承IHttpModule 扩展HttpModuleModule
public class MyCustomModule : IHttpModule
{
/// <summary>
/// 您将需要在网站的 Web.config 文件中配置此模块
/// 并向 IIS 注册它,然后才能使用它。有关详细信息,
/// 请参见下面的链接: http://go.microsoft.com/?linkid=8101007
/// </summary>
#region IHttpModule Members public void Dispose()
{
//此处放置清除代码。
} public void Init(HttpApplication application)
{
application.AcquireRequestState += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "AcquireRequestState "));
application.AuthenticateRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "AuthenticateRequest "));
application.AuthorizeRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "AuthorizeRequest "));
application.BeginRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "BeginRequest "));
application.Disposed += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "Disposed "));
application.EndRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "EndRequest "));
application.Error += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "Error "));
application.LogRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "LogRequest "));
application.MapRequestHandler += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "MapRequestHandler "));
application.PostAcquireRequestState += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostAcquireRequestState "));
application.PostAuthenticateRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostAuthenticateRequest "));
application.PostAuthorizeRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostAuthorizeRequest "));
application.PostLogRequest += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostLogRequest "));
application.PostMapRequestHandler += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostMapRequestHandler "));
application.PostReleaseRequestState += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostReleaseRequestState "));
application.PostRequestHandlerExecute += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostRequestHandlerExecute "));
application.PostResolveRequestCache += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostResolveRequestCache "));
application.PostUpdateRequestCache += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PostUpdateRequestCache "));
application.PreRequestHandlerExecute += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PreRequestHandlerExecute "));
application.PreSendRequestContent += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PreSendRequestContent "));
application.PreSendRequestHeaders += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "PreSendRequestHeaders "));
application.ReleaseRequestState += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "ReleaseRequestState "));
application.RequestCompleted += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "RequestCompleted "));
application.ResolveRequestCache += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "ResolveRequestCache "));
application.UpdateRequestCache += (s, e) => application.Response.Write(string.Format("<h1 style='color:#00f'>来自MyCustomModule 的处理,{0}请求到达 {1}</h1><hr>", DateTime.Now.ToString(), "UpdateRequestCache ")); //context.AuthenticateRequest //验证请求,一般用来取得请求用户的信息
//context.PostAuthenticateRequest 已经获取请求用户的信息
//context.AuthorizeRequest 授权,一般用来检查用户的请求是否获得权限
//context.PostAuthorizeRequest 用户请求已经得到授权
//context.ResolveRequestCache 获取以前处理缓存的处理结果,如果以前缓存过,那么,不必再进行请求的处理工作,直接返回缓存结果
//context.PostResolveRequestCache 已经完成缓存的获取操作
//context.PostMapRequestHandler 已经根据用户的请求,创建了处理请求的处理器对象
//context.AcquireRequestState 取得请求的状态,一般用于Session
//context.PostAcquireRequestState 已经取得了Session
//context.PreRequestHandlerExecute 准备执行处理程序
//context.PostRequestHandlerExecute 已经执行了处理程序
//context.ReleaseRequestState 释放请求的状态
//context.PostReleaseRequestState 已经释放了请求的状态
//context.UpdateRequestCache 更新缓存
//context.PostUpdateRequestCache 已经更新了缓存
//context.LogRequest 请求的日志操作
//context.PostLogRequest 已经完成了请求的日志操作 } #endregion
}
我们自己的Controller中写的Action就是在PreRequestHandlerExecute事件跟PostRequestHandlerExecute时间之间执行
Pre刚到这个事件 Post当前事件执行完毕
在这里会通过MvcRouteHandler找到一个执行当前请求的Handler 源码中在System.Web.MVC找MvcRouteHandler
2.写入配置文件Web.config
在system.webServer 标签中 的Modules里
<modules runAllManagedModulesForAllRequests="true">
<add name="MyCustomerModule" type="命名空间+类名,程序集名"/>
</modules>
3.框架默认有一套HttpModule 如果知道不需要其中某些HttpModule 移除指定的HttpModule
<modules runAllManagedModulesForAllRequests="false">
<remove name="FormsAuthentication" />
<remove name="WindowsAuthentication" />
<remove name="PassportAuthentication" />
<remove name="RoleManager" />
<remove name="FileAuthorization" />
<remove name="UrlAuthorization" />
</modules>
***************
之前版本的Asp.Net MVC正是通过 UrlRoutingModule.cs 类和 MvcHandler.cs 类进行扩展从而实现了MVC框架。
**************************
而在Asp.Net Core里面,管道模型流程发生了很大的变化:
IHttpModule和IHttpHandler不复存在,取而代之的是一个个中间件(Middleware)。
*********ASP.NET管道和.NET Core管道区别
http://www.cnblogs.com/niklai/p/5665272.html
**********MVC源码学习
https://www.cnblogs.com/landeanfen/p/5989092.html
Http请求处理流程 管道流程 MVC扩展HttpModule的更多相关文章
- Asp.net 面向接口可扩展框架之“Mvc扩展框架及DI”
标题“Mvc扩展框架及DI”有点绕口,我也想不出好的命名,因为这个内容很杂,涉及多个模块,但在日常开发又密不可分 首先说Mvc扩展框架,该Mvc扩展就是把以前的那个Mvc分区扩展框架迁移过来,并优化整 ...
- 面向接口可扩展框架之“Mvc扩展框架及DI”
面向接口可扩展框架之“Mvc扩展框架及DI” 标题“Mvc扩展框架及DI”有点绕口,我也想不出好的命名,因为这个内容很杂,涉及多个模块,但在日常开发又密不可分 首先说Mvc扩展框架,该Mvc扩展就是把 ...
- ASP.NET MVC扩展库
很多同学都读过这篇文章吧 ASP.NET MVC中你必须知道的13个扩展点,今天给大家介绍一个ASP.NET MVC的扩展库,主要就是针对这些扩展点进行.这个项目的核心是IOC容器,包括Ninject ...
- IT的灵魂是流程,流程的灵魂是业务,业务的灵魂是战略
IT的灵魂是流程,流程的灵魂是业务,业务的灵魂是战略.高效的IT平台不在于IT技术,而在于好的管理模式与流程设计 从以组织为核心转向以流程为核心 流程管理核心是从流程角度出发,关注流程是否增值,籍此建 ...
- 工作流activiti-03数据查询(流程定义 流程实例 代办任务) 以及个人小练习
在做数据查询的时候通过调用api来查询数据是相当的简单 对分页也进行了封装listPage(0, 4) ;listPage:分页查询 0:表示起始位置,4:表示查询长度 但是公司的框架封装了分页数据 ...
- MVC 扩展 Html.ImageFor
Asp.Net MVC 扩展 Html.ImageFor 方法详解 背景: 在Asp.net MVC中定义模型的时候,DataType有DataType.ImageUrl这个类型,但htmlhelpe ...
- MVC扩展ModelBinder使类型为DateTime的Action参数可以接收日期格式的字符串
原文:MVC扩展ModelBinder使类型为DateTime的Action参数可以接收日期格式的字符串 如何让视图通过某种途径,把符合日期格式的字符串放到路由中,再传递给类型为DateTime的控制 ...
- 前端基于easyui的mvc扩展(续)
前端基于easyui的mvc扩展(续) 回顾及遗留问题 上一篇讲解了基于easyui的mvc扩展的基本实现,已经降低了在mvc内使用easyui的难度,但是仍然还有一些问题: 当我们要给生成的控件设置 ...
- Gemini.Workflow 双子工作流入门教程三:定义流程:流程节点、迁移条件参数配置
简介: Gemini.Workflow 双子工作流,是一套功能强大,使用简单的工作流,简称双子流,目前配套集成在Aries框架中. 下面介绍本篇教程:定义流程:流程节点.迁移条件参数配置. 一.普通节 ...
随机推荐
- Java连接数据库 #01# JDBC单线程适用
官方教程(包括 javase的基础部分):JDBC Basics 重新梳理.学习一下“Java连接数据库”相关的内容. 因为最开始没有认真学多线程和JDBC,一直在自己写的多线程程序中维持下面的错误写 ...
- php 采集爬取单个淘宝商品描述,商品属性
下载链接:https://download.csdn.net/download/a724008158/10723448 效果图:
- RGB颜色对照表
RGB颜色对照表 https://www.cnblogs.com/android100/p/android-rgb-list.html #FFFFFF #FFFFF0 #FFFFE0 ...
- 让bat批处理后台运行,不显示cmd窗口(完全静化)
背景:由于我有某云的服务器(win server), 上面挂有好几个程序, 为了更好的监控他们, 我使用了一个最笨的方法, 就是下面的方法. 实现:我要监控的程序有三个, 成为ABC吧, 下面先把三个 ...
- Black Hat Python3 Chapter4
mail sniffer 现在的邮箱应用我能找到的都是加密传输了,因此相像书中那样直接从抓到的包里获取到用户名和密码信息除非是自己专门搭建一个邮箱服务器,不然很难做到,为了便于理解代码的运行,多添加一 ...
- 位运算之a^b
题目链接:https://www.acwing.com/problem/content/91/ 参考链接:https://blog.csdn.net/chaiwenjun000/article/det ...
- Auto.js 初试-Android开发JS利器
GitHub地址:https://github.com/hyb1996/Auto.js 文档地址:https://hyb1996.github.io/AutoJs-Docs/#/?id=%E7%BB% ...
- HTTP协议和XMPP协议、MQTT协议
应用层协议:每个应用层的都是为了解决某一类应用问题.而问题的解决又必须通过位于不同主机中的多个应用进程之间的通信和协同工作来完成.应用进程之间必须遵守严格的规则.应用层协议应当定义如下几个: 应用进程 ...
- Nikto
https://cirt.net/nikto2 Fire Up Kali & Open Nikto Let's fire up Kali and get started with nikto. ...
- topcoder srm 320 div1
problem1 link 两个数字后面都有阶乘符号,可以抵消. import java.util.*; import java.math.*; import static java.lang.Mat ...