ASP.NET Complete Life Cycle
来源:互联网 发布:本地文件夹同步软件 编辑:程序博客网 时间:2024/06/04 19:31
Introduction
Since too many resources are shared on the process level (i.e. IIS, inetinfo.exe) and it is too easy for an error to bring down the entire server process, ASP.NET provides an out-of-process execution model, which protects the server process from user code.
Life cycle of an ASP.NET application starts when the browser requests a page from the Web Server.
ISAPI.dll resides inside the Web Server, which examines the file extension of the requested file and determines which ISAPI extension should handle the request.
ISAPI.dll uses a named pipe and forwards a request to IIS where it runs inetinfo.exe to an instance of ASP.NET worker process aspnet_wp.exe. The worker process uses an instance of the HttpRuntime class to process the request.
By default, there will be only one worker process in use at a time.
If the file extension has been mapped successfully then a class named ApplicationManager is called which creates an Application Domain.
Application DomainApplication Domain provides isolation between different applications for global variables and allows each application to be unloaded separately.
Multiple Application Domains can run in a Single Process.
Why Isolation?
Single process can have multiple threads, memory leak, out-of-bound memory access, null object referencing, etc. If one of the applications crashes because of these, then all the application crashes; therefore, Isolation of application is required.
HostingEnvironment
An instance of a class named HostingEnvironment is created which resides in Application Domain.
Once the Application Domain is created and HostingEnvironment object is instantiated, Http requests are passed to an instance of the HttpRuntime class. HttpRuntime object examines the request and figures out which application it was sent to (i.e. virtual directory). It the uses HttpApplicationFactory to either find or create an HttpApplication object to process the request.
ASP.NET creates and initializes the core objects such as HttpContext, HttpRequest and HttpResponse.
After all the core objects are initialized, the application is started by creating an instance of the HttpApplication class. HttpApplication holds a collection of Http module objects
Application is started by creating an instance of the HttpApplication class. If the application contains Global.asax, it overrides the Global.asax file, which is derived from the HttpApplication.
The first time an ASP.NET page or process is requested in an application, a new instance of HttpApplication is created. To maximize performance, HttpApplication instances might be reused for multiple requests.
An instance of HttpApplication processes only one request at a time.
The following are the events which are called during the application life cycle.
1. Application_Start: It is called when the first resource in an ASP.NET application is requested.
2. Application_event: It is called at the appropriate time during the application life cycle.
Some of the Application events are as follows.
Application_BeginRequest: Whenever ASP.NET responds to the Request, it will be the first to occur in the Http Pipeline.
Handler
Listing 1
public event EventHandler BeginRequest;
Application_AuthenticateRequest: Occurs whenever the identity of the user has to be established.
Handler
Listing 2
public event EventHandler AuthenticateRequest;
Application_AuthorizeRequest: Occurs whenever the identity of the user has been verified.
Handler
Listing 3
public event EventHandler AuthorizeRequest;
Application_Error: Occurs when ever the unhandled exception is thrown.
Handler
Listing 4
public event EventHandler Error;
Application_EndRequest: Whenever ASP.NET responds to the Request, it will be the last to occur in the Http Pipeline chain.
Handler
Listing 5
public event EventHandler EndRequest;
3. HttpApplication.Init: called once for every instance of the HttpApplication class.
4. Application_End: Called once per lifetime of the application before the application is unloaded.
ConclusionThis article briefly examined the lifecycle of an ASP.NET application. It also discussed some of the HttpApplication events.
- ASP.NET Complete Life Cycle
- ASP.NET Page Life Cycle
- Asp.net Page Life-cycle
- The ASP.NET Page Life Cycle
- ASP.NET Page Life Cycle - 1
- ASP.NET Page Life Cycle Overview (2011)
- ASP.NET Application and Page Life Cycle
- ASP.NET Page Life Cycle Overview
- ASP.NET Page Life Cycle Overview
- ASP.NET - Application Life Cycle Principle
- ASP.NET Page Life Cycle Events
- ASP.NET 应用程序生命周期(ASP.NET Application Life Cycle)
- Explain the page life cycle in ASP.NET 2.0
- ASP.NET application and page life cycle -2
- .NET: A Complete Development Cycle
- .NET-A Complete Development Cycle (re-link)
- The Project Management Life Cycle: A Complete Step-By-Step Methodology For Initiating, Planning, Exe
- Servlet life cycle
- 开个技术blog-开篇:虚拟化技术小结
- Java命令参数
- 考考你,能看出这一段代码是用哪个编程语言写的吗?
- 使用技巧:共享内存在Java中实现和应用
- 女孩进来自测一下
- ASP.NET Complete Life Cycle
- linux中Daemon进程
- Spring框架与AOP思想的研究与应用
- 我用“电驴”抓肉鸡(转)
- JMX 技术的认识
- static 变量
- Log4j基本知识-备忘!!!
- 利用JBossMX开发标准MBean(经典!转)
- A*寻路初探 GameDev.net