码迷,mamicode.com
首页 > 其他好文 > 详细

Life Cycle Stages of IIS 7.0

时间:2020-07-19 00:41:52      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:example   text   pac   started   processes   wan   -name   let   isa   

Life Cycle Stages

The following table lists the stages of the ASP.NET application life cycle with Integrated mode in IIS 7.0.

1.A request is made for an application resource.

The life cycle of an ASP.NET application starts with a request sent by a browser to the Web server.

In Classic mode in IIS 7.0 and in IIS 6.0, the ASP.NET request pipeline is separate from the Web server pipeline. Modules apply only to requests that are routed to the ASP.NET ISAPI extension. If the file-name extension of the requested resource type is not explicitly mapped to ASP.NET, ASP.NET functionality is not invoked for the request because the request is not processed by the ASP.NET runtime.

IIS 7.0里面的经典模式和IIS 6.0里面的 request管线是和web server的管线分开的,modules仅对route到ASP.NET ISAPI扩展的request起作用。

如果请求的资源类型的文件名后缀没有显式地映射到ASP.NET,那么ASP.NET的功能就不会被调用。

In integrated mode in IIS 7.0, a unified pipeline handles all requests. When the integrated pipeline receives a request, the request passes through stages that are common to all requests. These stages are represented by the RequestNotification enumeration. All requests can be configured to take advantage of ASP.NET functionality, because that functionality is encapsulated in managed-code modules that have access to the request pipeline. For example, even though the .htm file-name extension is not explicitly mapped to ASP.NET, a request for an HTML page still invokes ASP.NET modules. This enables you to take advantage of ASP.NET authentication and authorization for all resources.

 在IIS 7.0的集成模式下,一个统一的管线会处理所有的请求。当集成管线收到一个请求,这个请求会通过所有的stages。

RequestNotification这个枚举里面的数值,对应了不同的stages。这些stages对应了HttpApplication里面的event。

using System;

namespace System.Web
{
    /// <summary>Indicates when events and other life-cycle events occur while a <see cref="T:System.Web.HttpApplication" /> request is being processed.</summary>
    // Token: 0x020000ED RID: 237
    [Flags]
    public enum RequestNotification
    {
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.BeginRequest" /> event was raised for the request and is processing.</summary>
        // Token: 0x0400057C RID: 1404
        BeginRequest = 1,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.AuthenticateRequest" /> event was raised for the request and is processing.</summary>
        // Token: 0x0400057D RID: 1405
        AuthenticateRequest = 2,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.AuthorizeRequest" /> event was raised for the request and is processing.</summary>
        // Token: 0x0400057E RID: 1406
        AuthorizeRequest = 4,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.ResolveRequestCache" /> event was raised for the request and is processing.</summary>
        // Token: 0x0400057F RID: 1407
        ResolveRequestCache = 8,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.MapRequestHandler" /> event was raised for the request and is processing.</summary>
        // Token: 0x04000580 RID: 1408
        MapRequestHandler = 16,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.AcquireRequestState" /> event was raised for the request and is processing.</summary>
        // Token: 0x04000581 RID: 1409
        AcquireRequestState = 32,
        /// <summary>Indicates a point in the application life cycle just before the handler that processes the request is mapped.</summary>
        // Token: 0x04000582 RID: 1410
        PreExecuteRequestHandler = 64,
        /// <summary>Indicates that the handler that is mapped to the requested resource is being invoked to process the request.</summary>
        // Token: 0x04000583 RID: 1411
        ExecuteRequestHandler = 128,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.ReleaseRequestState" /> event was raised for the request and is processing.</summary>
        // Token: 0x04000584 RID: 1412
        ReleaseRequestState = 256,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.UpdateRequestCache" /> event was raised for the request and is processing.</summary>
        // Token: 0x04000585 RID: 1413
        UpdateRequestCache = 512,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.LogRequest" /> event was raised for the request and is processing.</summary>
        // Token: 0x04000586 RID: 1414
        LogRequest = 1024,
        /// <summary>Indicates that the <see cref="E:System.Web.HttpApplication.EndRequest" /> event was raised for the request and is processing.</summary>
        // Token: 0x04000587 RID: 1415
        EndRequest = 2048,
        /// <summary>Indicates that processing of the request is complete and that the response is being sent.</summary>
        // Token: 0x04000588 RID: 1416
        SendResponse = 536870912
    }
}

 

2.The unified pipeline receives the first request for the application.

When the unified pipeline receives the first request for any resource in an application, an instance of the ApplicationManager class is created, which is the application domain that the request is processed in. Application domains provide isolation between applications for global variables and enable each application to be unloaded separately. In the application domain, an instance of the HostingEnvironment class is created, which provides access to information about the application, such as the name of the folder where the application is stored.

During the first request, top-level items in the application are compiled if required, which includes application code in the App_Code folder. You can include custom modules and handlers in the App_Code folder as described in Managed-code Modules in IIS 7.0 later in this topic.

收到请求后,首先创建ApplicationManager,这个是一个用来处理request的application domain。并且它会创建HostingEnvironment。第一个请求的时候,还会编译Application的顶级的items,比如App_Code下面的自定义modules和handlers。

 

3.Response objects are created for each request.

After the application domain has been created and the HostingEnvironment object has been instantiated, application objects such as HttpContextHttpRequest, and HttpResponse are created and initialized.

The HttpContext class contains objects that are specific to the current application request, such as the HttpRequest and HttpResponse objects.

The HttpRequest object contains information about the current request, which includes cookies and browser information.

The HttpResponse object contains the response that is sent to the client, which includes all the rendered output and cookies.

The following are some key differences between IIS 6.0 and IIS 7.0 running in Integrated mode and with the .NET Framework 3.0 or later:

 为每一个请求创建response对象。在application domain创建以后,并且HostingEnvironment对象也初始化之后,上下文,请求,回复也都创建摈弃给初始化了。

 

4.An HttpApplication object is assigned to the request

After all application objects have been initialized, the application is started by creating an instance of the HttpApplication class. If the application has a Global.asax file, ASP.NET instead creates an instance of the Global.asax class that is derived from the HttpApplication class. It then uses the derived class to represent the application.

 Note

The first time that an ASP.NET page or process is requested in an application, a new instance of the HttpApplication class is created. However, to maximize performance, HttpApplication instances might be reused for multiple requests.

Which ASP.NET modules are loaded (such as the SessionStateModule) depends on the managed-code modules that the application inherits from a parent application. It also depends on which modules are configured in the configuration section of the application‘s Web.config file. Modules are added or removed in the application‘s Web.config modules element in the system.webServer section. For more information, see How to: Configure the <system.webServer> Section for IIS 7.0.

在所有的application对象初始化完成后,通过创建一个HttpApplication的实例来启动application。有哪些modules被加载,取决于从父application那边继承的以及自己的配置文件里面配置的。

 

5.The request is processed by the HttpApplication pipeline.

The following tasks are performed by the HttpApplication class while the request is being processed. The events are useful for page developers who want to run code when key request pipeline events are raised. They are also useful if you are developing a custom module and you want the module to be invoked for all requests to the pipeline. Custom modules implement the IHttpModule interface. In Integrated mode in IIS 7.0, you must register event handlers in a module‘s Init method.

  1. Validate the request, which examines the information sent by the browser and determines whether it contains potentially malicious markup. For more information, see ValidateRequest and Script Exploits Overview.

  2. Perform URL mapping, if any URLs have been configured in the UrlMappingsSection section of the Web.config file.

  3. Raise the BeginRequest event.

  4. Raise the AuthenticateRequest event.

  5. Raise the PostAuthenticateRequest event.

  6. Raise the AuthorizeRequest event.

  7. Raise the PostAuthorizeRequest event.

  8. Raise the ResolveRequestCache event.

  9. Raise the PostResolveRequestCache event.

  10. Raise the MapRequestHandler event. An appropriate handler is selected based on the file-name extension of the requested resource. The handler can be a native-code module such as the IIS 7.0 StaticFileModule or a managed-code module such as the PageHandlerFactory class (which handles .aspx files). 

  11. Raise the PostMapRequestHandler event.

  12. Raise the AcquireRequestState event.

  13. Raise the PostAcquireRequestState event.

  14. Raise the PreRequestHandlerExecute event.

  15. Call the ProcessRequest method (or the asynchronous version IHttpAsyncHandler.BeginProcessRequest) of the appropriate IHttpHandler class for the request. For example, if the request is for a page, the current page instance handles the request.

  16. Raise the PostRequestHandlerExecute event.

  17. Raise the ReleaseRequestState event.

  18. Raise the PostReleaseRequestState event.

  19. Perform response filtering if the Filter property is defined.

  20. Raise the UpdateRequestCache event.

  21. Raise the PostUpdateRequestCache event.

  22. Raise the LogRequest event.

  23. Raise the PostLogRequest event.

  24. Raise the EndRequest event.

  25. Raise the PreSendRequestHeaders event.

  26. Raise the PreSendRequestContent event.

     Note

    The MapRequestHandlerLogRequest, and PostLogRequest events are supported only if the application is running in Integrated mode in IIS 7.0 and with the .NET Framework 3.0 or later.

请求通过Application的管线进行处理。

 

Life Cycle Stages of IIS 7.0

标签:example   text   pac   started   processes   wan   -name   let   isa   

原文地址:https://www.cnblogs.com/chucklu/p/13338006.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!