As we all know, in asp.net, If we modify the configuration file, we only need to save it and then immediately respond to the program. We do not need to restart IIS. You can even directly replace the files in the application without stopping IIS, including the compiled dll files. All you need to do is replace the files you have changed. So how does. net do it?
This is due to the. net application domain mechanism. The application domain is a metaunit smaller than the process, that is, a process can contain multiple application domains. Each domain is independent and does not share memory. That is to say, various static variables are not shared among different domains.
With the application domain, it is easy to do things. When we change the configuration file or replace a core dll, then. net Monitoring System will report what we do, so the process processing asp.net will re-create an application domain for the modified application, this new domain will reflect all the changes. If a Request comes in, the new domain will be used for processing, and the original domain will be destroyed.
In fact, each application domain is not a dll file configured in each virtual directory. For 2.0, 3.0, 3.5, C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ Temporary ASP.. NET Files directory, so we can directly replace Files such as dll.
We can perform a simple test on creating application domains. Add the following processing code to the Application_BeginRequest event in the global file to name the application domain of each request to the trace file. To make it clear, we use the wran method.
Context. Trace. Warn ("MyCatolog", "Domain Name:" + AppDomain. CurrentDomain. FriendlyName );
Finally, do not forget to set Trace in the configuration file.
<Trace enabled = "true" pageOutput = "true" requestLimit = "44" traceMode = "SortByTime" mostRecent = "true"/>
Now we can access our page.
Trace:
Then let's change the configuration file, for example, change requestLimit to 10, save the file, and access it again, as shown in figure
We can see that the domain name has changed, that is, this is a new application domain.