Upon serving a request for an ASPX page, if ASP.NET notices any change to that page, it will automatically recompile the page into an assembly and use that new page definition to handle to the request.
As far as I know, .NET doesn’t allow us to unload an assembly from an application domain. However, it does allow us to unload the whole application domain (with its assemblies). Therefore, it seems to me that the only way ASP.NET can replace the old assembly with the new assembly (of the updated ASPX file) is unloading the whole application domain and create a new one to host the web application (which is effectively a application restart, which happens when the web.config is changed, assemblies bin folder are updated etc.) However, I notice that it seems not to be the case as the application responds much more quickly after I modify an ASPX file than when I modify the web.config file.
Therefore, my question is: is it possible for ASP.NET to load new version of the assembly of an ASPX page without having to unload the whole application and create a new one?
ASP.NET can’t unload the old assembly without the restarting the application, but it can ignore the old assembly and start using the newly compiled version of your page. A new assembly is compiled and loaded (actually containing the whole folder rather than just the one changed page) and subsequent requests use that new assembly.
You can see the change of assembly by writing out the assembly name in your page:
With two pages in different folders you’ll see that the changed page moves to a new assembly, while the other page is unaffected.
To avoid gradually filling up memory with old assemblies, the application will occasionally be restarted in response to a change. By default this is every 15 changes, though you can adjust that in web.config with