IIS & Application Pool & App Domain & ...

http://stackoverflow.com/questions/13319996/httpmodules-and-global-asax-asp-net-page-life-cycle

ASP.NET applications in IIS are structured like my image below. I know it is probably scary looking but the names should sound familiar. Hopefully the familiar names make it a little more digestible.

I'm not going to rehash in words the structure you see below. The picture does a better job then I could ever say in sentences. Instead, I'll jump right in to the implications the image has for your questions.


App Domain
What is an App Domain? It is as a private allotment of system memory for an application. All code inside the domain uses the allocated domain memory. This means static types and references are shared in a domain. All code outside the domain can't access the domain's memory.

Every ASP.NET application is runs inside one App Domain for each App Pool it belongs to. This one to one relationship holds true regardless of the thread count in an App Pool.

Global.asax
What is Global.asax? At its simplest it is a .NET class that inherits from System.Web.HttpApplication.HttpApplication gives Global.asax the smarts to guide all HTTP Requests through the request pipeline. It will fire all the request life-cycle events and call ProcessRequest on the handler.

Each ASP.NET application will create multiple instances of HttpApplication (Global.asax). When a request is received it will be handed to one of the HttpApplication instances. The request will then stay with the sameHttpApplication instance for its lifetime. This means there is one HttpApplication instance per request being handled. Every HttpApplication instance can, and will, be reused to handle many requests during its lifetime.

Aplication Events
Where do the Application events like Application_Start tie in? That depends since some of these events refer to the App Domain and some to HttpApplication. Application_Start and Application_End refer to the start and end of the App Domain. The rest of the Application events (e.g. Application_Begin) refer to the life-cycle of anHttpApplication instance.

More Information
For more information I suggest this MSDN article and this non-MSDN article.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章