gpt4 book ai didi

asp.net - IIS 加载 ASP.NET Web 应用程序的哪些 dll 文件?

转载 作者:行者123 更新时间:2023-12-02 11:16:49 24 4
gpt4 key购买 nike

我找不到任何相关信息。有谁知道IIS是否加载Web应用程序bin目录中的所有dll或任何目录中的所有dll或者仅加载项目引用的目录(在这种情况下它如何确定哪个dll是“master”)?

我刚刚遇到过一种情况,有人在部署新版本之前没有从 Web 应用程序目录中删除所有文件,而某些 dll 被重命名。该冗余 dll 位于 MVC 4 Web 应用程序的 bin 目录中。

最佳答案

作为实验,我创建了一个新的 ASP.NET Webforms 项目,并将其部署到 IIS。然后,我创建了第二个 .net 类库,并将 .dll 文件复制到 Web 应用程序的 \bin 文件夹(该类库未在 ASP.NET 应用程序中的任何位置引用或使用)。

我启动了 SysInternals ProcMon,在 IIS 中回收了应用程序池和网站,并在浏览器中请求了该网站。

w3wp.exe 确实在首页请求时读取了类库 .dll 文件。

<小时/>

This MSDN page还指出:

You can store compiled assemblies in the Bin folder, and other code anywhere in the web application (such as code for pages) automatically references it. A typical example is that you have the compiled code for a custom class. You can copy the compiled assembly to the Bin folder of your Web application and the class is then available to all pages.

Assemblies in the Bin folder do not need to be installed in the Global Assembly Cache (GAC). The presence of a .dll file in the Bin folder is sufficient for ASP.NET to recognize it.

这似乎意味着 ASP.NET 将反射(reflect)它在 \bin 中找到的程序集并自动加载它们。

<小时/>

有趣的是,即使您将非 .net 文件(我从 C:\Windows 复制了 twain.dll)放入 ASP.NET bin 文件夹中,这些文件也会被读取。运行时似乎只是向文件系统询问 \bin\* 并循环遍历文件以检查是否要加载 .NET 程序集。

<小时/>

我还注意到,如果您将其添加到您的 web.config 文件中:

  <system.web>
<compilation targetFramework="4.5">
<assemblies>
<clear />
</assemblies>
</compilation>

然后页面将不再运行,并出现错误

Could not load type 'WebApplication1.Global'.

因此,运行时似乎不再从程序集中加载这些类。 但是,运行时仍然从驱动器中读取非引用控制台应用程序 .dll 和非 .net 程序集 twain.dll。

因此,答案归结为“加载所有 dll”的含义...如果您的意思是在运行时可用,那么如果您指定自己的系统,那么答案就是“否” .web |编译|程序集,但默认是加载全部。但如果您的意思是物理读取哪些文件,那么"is"。

关于asp.net - IIS 加载 ASP.NET Web 应用程序的哪些 dll 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33167715/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com