IIS加载ASP.NET Web应用程序的哪些dll文件? [英] Which dll files of ASP.NET web application does IIS load?

查看:120
本文介绍了IIS加载ASP.NET Web应用程序的哪些dll文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到有关它的任何信息.有人知道IIS是加载Web应用程序的bin目录中的所有dll还是加载任何目录中的所有dll,或者仅加载项目引用的目录(在这种情况下,它是如何确定哪个DLL是主")的?

I couldn't find any information about it. Does anybody know whether IIS load all dlls in bin directory of web application or all dlls in any directory or maybe only directories referenced by project (in this case how it determines which dll is "master")?

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

I've just had a situation where someone didn't remove all files from web application directory before deploying new version, while some dll was renamed. This redundant dll was in bin directory of MVC 4 web application.

推荐答案

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

As an experiment I made a new ASP.NET Webforms project, and deployed it to IIS. I then made a 2nd .net class library, and copied the .dll file to the web app's \bin folder (the class library is not referenced or used anywhere in the ASP.NET app).

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

I started up SysInternals ProcMon, recycled the app pool and web site in IIS, and requested the site in a browser.

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

w3wp.exe does indeed read the class library .dll file on first page request.

此MSDN页面还指出:

您可以将已编译的程序集存储在Bin文件夹中,并且Web应用程序中任何其他代码(例如页面代码)都会自动引用它.一个典型的示例是您具有自定义类的已编译代码.您可以将已编译的程序集复制到Web应用程序的Bin文件夹中,然后该类可用于所有页面.

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.

Bin文件夹中的程序集不需要安装在全局程序集缓存(GAC)中. Bin文件夹中存在.dll文件足以使ASP.NET识别它.

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将反映它在\bin中找到的程序集并自动加载它们.

Which does seem to imply that ASP.NET will reflect over the assemblies it finds in \bin and automatically load them.

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

Interestingly, even if you put a non-.net file (I copied twain.dll from C:\Windows) into your ASP.NET bin folder, those files are also read. The runtime seems to just ask the filesystem for \bin\* and loops over the files to check for .NET assemblies to load.

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

I also noticed that if you add this to your web.config file:

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

然后该页面将不再运行,并显示错误

Then the page will no longer run, with the error

无法加载类型'WebApplication1.Global'.

Could not load type 'WebApplication1.Global'.

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

So it seems that the runtime no longer loads those classes from the assemblies. However, the runtime still reads the non-referenced console application .dll and non-.net assembly twain.dll off the drive.

因此,答案归结为您所说的加载所有dll"的含义...如果您的意思是使它们在运行时可用,那么如果您指定自己的system.web | compilation | assemblies,则答案为否".默认为全部加载.但是,如果您要实际读取的是文件,则为是".

So, the answer comes down to what you mean by "loads all dlls" ... If you mean makes available in the runtime, then the answer is sort-of "no" if you specify your own system.web | compilation | assemblies but the default is to load all. But if you mean what files are physically read, then "yes".

这篇关于IIS加载ASP.NET Web应用程序的哪些dll文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆