Application Pools:This is a new concept for Microsoft: An application pool is a configuration that links one or more applications to one or more worker process collections. Because applications in application pools are separated from other applications by worker process boundaries, applications in one application pool are not affected by the problems that are caused by applications in other application pools. application domain:
As we all know,. NET written programs are managed and what is managed? is to let "other programs" to manage, also parse the run, what is here to act as "other program"? This is largely the CLR (Common Language Runtime), which is just a matter of how exactly the underlying relationship between managed programs and the operating system is handled.
Processes are running on the operating system, which is unmanaged. Right now. We have a Demo.exe, which is written in. NET (this is not about language, because it becomes the IL language after it is set up as an assembly), and of course it is a management program. The problem here is how to turn Demo.exe into a process that runs in the process of the operating system. This leads to the application domain (application domain), the application domain (application domain) is "the bridge between the management code and the non-entrusted Management Code" (quoted from the. NET component Programming Design ")
The relationship between the process, application domain, and. NET assembly (here is Demo.exe) can be seen in the following:
(Figure 1) there can be more than one application domain (application domain) in a process, and there can be multiple assemblies in an application domain (application domain).
The advantage of introducing application domains (application domain) is that if an assembly has an error, it does not affect other application domains (application domain), and they are also in a process.
In. NET, the application domain (application domain) is represented by the AppDomain class.
AppDomain Currentad=appdomain.currentdomain;
The above code implements the fetch when there is an application domain (application domain) where the assembly resides. Getting the current application domain (application domain) is also available through the current thread, as follows:
AppDomain Currentad=threed.getdomain ();
Here's another look. Create an object in the current application domain (application domains):
Class:
Class Class1
{
public void FF ()
{
Implementation features
}
{
AppDomain Currentad=threed.getdomain ();
Class1 c1= (CLASS1) currentad.createinstanceandunwrap ("assembly name", "name space. Class name");
C1. FF ();
This is about the operation of the current application domain (application domain), how to create an application domain (application domain)? Look underneath.
AppDomain Myappdomain=appdomain.creatdomain ("Mynewad");
Class1 c1= (Class1)Myappdomain. Createinstanceandunwrap ("assembly name", "name space. Class name");
C1. FF ();
Or
AppDomain Myappdomain=appdomain.creatdomain ("Mynewad");
IObjectHandle handle=myappdomain. CreateInstance "assembly name", "name space. Class name");
Class1 c1= (CLASS1) handle. Unwrap ();
C1. FF ();
The advantage of the latter is that it is only in the process of C1 the object.
First of all, application Pool was a concept in IIS, but the AppDomain is a concept in. NET. You can write your own program to use 2 or more appdomaines.
First, the application pool is the concept in IIS, and the application domain is the concept in. Net. You can write a program that runs on 2 or more application domains.
I did a test with the IIS7 ASP. 2.0 on my Vista computer.
I did a test on my Vista computer IIS7 aps.net2.0.
Here is the test code:
Here is the test code:
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
string info;
info = "Current Process Name:" + process.getcurrentprocess (). ProcessName + "
";
info + = "Current Process Id:" + process.getcurrentprocess (). Id + "
"; info + = "Current application Domain:" +appdomain.currentdomain.friendlyname + "
";
info + = "Current application Domain Base Dir:" +appdomain.currentdomain.basedirectory + "
";
divinfo.innerhtml = info;
}
} Now, I created 2 application pools called AppPool1 and AppPool2;
Now, I build 2 application pools AppPool1 and AppPool2;
Then I created 3 applications called AppTest1, AppTest2 and AppTest3. All of them-the same directory where my sample is. I put AppTest1 under AppPool1, AppTest2 and AppTest2 under. Then I set up 3 sites: AppPool2 application pool for AppTest1 and Apppool1.apptest2 should The program pool is AppPool2. All points to the newly created site directory. Here is the result:
Here is the return result:
Http://localhost/AppTest1/Default.aspxCurrent Process name:w3wp
Current Process id:3784
Current Application domain:/lm/w3svc/1/root/apptest1-2-128701111683637820
Current application Domain Base dir:c:\inetpub\wwwroot\apptest\
Http://localhost/AppTest2/Default.aspxCurrent Process name:w3wp
Current Process id:5044
Current Application domain:/lm/w3svc/1/root/apptest2-1-128701111868733395
Current application Domain Base dir:c:\inetpub\wwwroot\apptest\
Http://localhost/AppTest3/Default.aspxCurrent Process name:w3wp
Current Process id:5044
Current Application domain:/lm/w3svc/1/root/apptest3-2-128701113026462030
Current application Domain Base dir:c:\inetpub\wwwroot\apptest\ This is the conclusion:here is the conclusion:
The IIS process is w3wp;iis processes are w3wp;
Every application pool in IIS use it "s own process; AppPool1 uses process 3784, APPPOOL2 uses process 5044 Each IIS application pool has its own process AppPool1 with process 3784. AppPool2 with Process 5044
Different applications in ASP. Use Different AppDomain; different ASP. NET sites with different application domains;
AppTest2 and AppTest2 is in different AppDomain, yet in the same process. Site AppTest2 and AppTest3 in different application domains, but within the same process.
What is the key to using them?
Application pool and AppDomain, both of them can provide isolations, but use different approches. Application pool Use the process to isolate the applications which works without. NET. But the AppDomain is another isolation methods provided by. NET. Both application pools and application domains can provide program isolation, but the use is different. The application pool is not in. NET environment can also provide inter-program isolation. And the application domain is. NET provides the means of isolation.
If Your server host thousands of Web sites, you wont use thousands of the application pool to isolate the Web sites, just Becuase, too many processes running would kill the OS. However, sometime you need application pool. One of the advantages for application pool is so you can config the identity for application pool. Also You has more flexible options to recyle the application pool. At least right now, IIS didnt provide explicit options to recyle the AppDomain.
If your server has thousands of sites, you will not use thousands of application pools to isolate the site, because too many processes are open on the server. However, sometimes you need an application pool. The benefit of an application pool is that you can configure the identity of the application pool. You can also recycle application pools in more flexible ways. IIS does not provide configuration parameters to recycle the application pool.
A question was asked in a forum that I frequent which I thought is worth writting a blog about.
Q:What is the difference between a application and an Appdomain? I understand from my the container within which ASPX runs and that AppPool are a process That starts the W3wp.exe worker process within which ASP applications run.
A:That ' s a good question. Here is some key differences:
- An application is a IIS term, but it's one that ASP. utilizes. Essentially it creates a sandbox, or a set of boundaries to separate different sites, or parts of sites, from the others.
- An AppDomain was a. NET term. (in IIS7, AppDomains play a larger role within IIS, but for the most part it's an ASP.)
- An AppDomain contains InProc session state (the default session, State mode). So if a AppDomain is killed/recycled, and all of the your session state information would be lost. (If you is using the default InProc session state)
- Applications can has multiple AppDomains in them although often times there is a one-to-one relationship between them.
- In IIS6 and greater, there are the option of creating groups, or "pools" of applications that can be bundled together or SE parated; However the server administer decides. These is called application pools. Each app pool runs under its own w3wp.exe worker process.
- In IIS, it's easy-to-see-an application. A new website is a separate application and any subfolder can being marked as an application. When they is, the icon beside the folder Turnes into a picture of some gears. By right-clicking to the folder, you have the option of marking a folder as an application or removing it as an applicatio N, if it already is one. Also, in IIS6, in the Application pools sections, you can see all of the applications and which app pool they live under.
- ASP., on the other hand, doesn ' t give much visibility to AppDomains, at least no from any visual tools. This was done behind the scenes. Programmatically can create them, tear them down or see a list of all running AppDomains.
- You can recycle a application from IIS. In IIS5, you can ' t do it directly unless recycle the entire Web server, but in IIS6 and greater, you can recycle the A Pplication pool that the application lives under. It would gracefully die off and a new application would start up to replace it. Or, to word it another, another w3wp.exe worker process would be started and then the old one would die off after it com Pletes any currently running page requests.
- You can recycle a AppDomain in ASP. Through the ' Touch trick '. There is a few ways to does it, but the most straight forward was to edit your Web. config file in Notepad and add a space to An insignificant place. Then save the file. This would cause the AppDomain to recycle. This *does not* touch the IIS application though.
- Recycling an AppDomain would come pretty close to starting ASP. Fresh again for that particular ASP. Although it doesn ' t recycle the AppPool, it can give ASP. NET a fresh start in many situations.
Understanding the AppDomain and AppPool