开发者

ASP.NET - bin Directory vs. Adding Assembly in web.conf

I am relatively new to ASP.NET programming (but not programming in general), and I have been looking through a project that has been handed off to me. Within this 开发者_JS百科project, there is a bin directory which contains a slew of various DLL files.

Then, in the web.conf file, inside the assemblies structure (within the XML), there is a slew of other assemblies being added.

I've done a search on both SO and through Google in general, and I am still struggling over what the difference is between the two. Is one way "better" than the other? Any clarification that can be provided would be most appreciated.

Thanks.


There are several ways to reference assemblies (DLLs, usually) in an ASP.NET application:

  1. Add the DLL to your application's "bin" directory. This creates an implicit reference in every code file and ASPX file in your application to that DLL. This means that code inside an ASPX file or inside a CS file in App_Code can use the types in that DLL.

  2. Add a reference to the DLL in the <assemblies> section in web.config. See MSDN for details on the syntax. There are generally multiple web.config files that apply to a particular web application. The application itself can have several web.config files (for example, a web.config in a particular folder might add its own references). There is also a global web.config (or machine.config) that has references available to all ASP.NET applications on the computer.

  3. Use the <%@ Assembly Name="" %> directive in a particular ASPX (or ASCX or MASTER) file. See MSDN for details on the syntax.

The references in a given file in an ASP.NET application is a combination of the applicable items above.

The reason you have to reference assemblies is that ASPX files (much like CS and VB files themselves) eventually get compiled by either the C# or VB compiler. In order for those compilers to know what types you want to use they need to know which assemblies contain those types.


The bin directory is a copy of all the dll's that are built and referenced by your project. When the web application is running, it looks in the bin directory for the physical dll's it needs to execute the web application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜