ASP.NET中HttpApplication中ProcessRequest方法中执行的事件顺序;ASP.NET WebForm和MVC整体请求流程图

ASP.NET中HttpApplication中ProcessRequest方法中执行的事件顺序

1.BeginRequest  开始处理请求

2.AuthenticateRequest 授权验证请求,获取用户授权信息
3.PostAuthenticateRequest 获取成功
4.AunthorizeRequest 授权,一般来检查用户是否获得权限
5.PostAuthorizeRequest 获得授权
6.ResolveRequestCache 获取页面缓存结果(如果没有则执行)
7.PostResolveRequestCache 已获取缓存
8.PostMapRequestHandler 创建页面对象
9.AcquireRequestState 获取Session -- 先判断当前页面对象是否实现了IRequiresSessionState接口,如果实现了,则从浏览器发来的请求报文头中获得SessionId,并到服务器的 Session池中获得对应的Session对象,最后赋值给 HttpContext的Session属性。
10.PostAcquireRequestState 获得Session
11.PreRequestHandlerExecute 准备执行页面对象
×执行页面对象的ProcessRequest方法(1.ashx,1.aspx),如果请求的是1.aspx,则会运行页面生命周期
12.PostRequestHandlerExecute 执行完页面对象了
13.ReleaseRequestState 释放请求状态
14.PostReleaseRequestState 已释放请求状态
15.UpdateReuqestCache 更新缓存
16.PostUpdateRequestCache 已更新缓存
17.LogRequest 日志记录
18.PostLogRequest 已完成日志

19.EndRequest 完成


可以再Global.asax中添加以Application_为前缀+事件名 的方法运行测试!例如:

 public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);  
        }

    
        public void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication obj = sender as HttpApplication;
            obj.Context.Response.Write("1 Application_BeginRequest
"); } public void Application_ResolveRequestCache(object sender, EventArgs e) { HttpApplication obj = sender as HttpApplication; obj.Context.Response.Write("6 Application_ResolveRequestCache
"); } public void Application_PostResolveRequestCache(object sender, EventArgs e) { HttpApplication obj = sender as HttpApplication; obj.Context.Response.Write("7 Application_PostResolveRequestCache
"); } public void Application_PreRequestHandlerExecute(object sender, EventArgs e) { HttpApplication obj = sender as HttpApplication; obj.Context.Response.Write("11 Application_PreRequestHandlerExecute
"); } } }


以下附上MVC整体请求流程图,来自传智播客黑马培训班ASP.NET中HttpApplication中ProcessRequest方法中执行的事件顺序;ASP.NET WebForm和MVC整体请求流程图_第1张图片


ASP.NET WebForm整体请求流程图,来自传智播客黑马培训班

ASP.NET中HttpApplication中ProcessRequest方法中执行的事件顺序;ASP.NET WebForm和MVC整体请求流程图_第2张图片


你可能感兴趣的:(ASP.NET,WebForm)