Does my ASP.NET application stop executing if I overwrite the DLLs?

后端 未结 2 1899
感动是毒
感动是毒 2020-12-30 04:22

Assume that my ASP.NET application is making 4 separate database calls. If after the 2nd call, I overwrite the DLLs in BIN folder, does it stop the application from continui

相关标签:
2条回答
  • 2020-12-30 04:48

    The assemblies are loaded into the app domain, and app domain watches the directory, if you replace the assemblies it will recycle the app and reload the assemblies. So yes your 3rd/4th calls would fail.

    0 讨论(0)
  • 2020-12-30 04:49

    ASP.NET performs a thing called shadow copying on various resources including DLLs and ResX files. When a file is accessed by the framework, it is locked preventing direct access. To prevent locking files within the root/bin or root/App*_Resources (for example), it copies these resources to a predetermined directory.

    [Edit]
    The predetermined directory defaults to something like

    C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\demo1\9b9144a7\8665ac07

    where demo1 is the name of your application and nested directories which (I assume) are hashed against the friendly name of the AppDomain for the contained resources.

    For instance, I have a directory called dbresourceproviderweb from a resource provider example on MSDN written by Michelle Bustamante. Inside that directory, there are two folders: c8b872e2 and 7fc33f08. To go further, compiled resources for Ecuadorian Spanish are under ...\dbresourceproviderweb\c8b872e2\97074f76\es-EC and ...\dbresourceproviderweb\7fc33f08\ac65ebd3\es-EC
    [/Edit]

    You can change this directory in Application_Start as explained here: AssemblyResolve event is not firing during compilation of a dynamic assembly for an aspx page

    You can turn off shadow copying in the web.config:

    <hostingEnvironment shadowCopyBinAssemblies="false" />

    When one of these shadow copied files is updated within your application, a new AppDomain is spawned and requests in the current AppDomain are allowed to finish while all new requests are directed at the new AppDomain.

    For more information on Shadow Copying and AppDomains, check out MSDN's article: http://msdn.microsoft.com/en-us/library/ms404279.aspx

    Edit2: I just learned that you can modify the required length of time between file copy operations to spawn an AppDomain.

    In the system.web/httpRuntime element, you can specify waitChangeNotification and maxWaitChangeNotification so that a new AppDomain isn't spawned for every file copied. See MSDN.

    Although there aren't really examples for this behavior on MSDN, it's good to keep as a reference for the configurability of the HttpRuntime.

    0 讨论(0)
提交回复
热议问题