Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 821
JasCav Avatar asked Jan 13 '10 21:01

JasCav


People also ask

What is the use of bin directory in asp net?

The Bin folder is used for managed-code assemblies, not for native-code (unmanaged-code) assemblies. For more information, see Loading C++ Assemblies in ASP.Net. In ASP.NET 2.0 and later versions, you can put strong-named (signed) assemblies in the Bin folder.

What is the Bin directory?

The /bin directory is found on Linux computers and stores all binary executables. This directory includes all the command line commands and other binary executables. 3. Bin is also an abbreviation sometimes used for the Windows Recycle Bin.

What is Appcode in c#?

The App_Code folder is automatically present in the project. It stores the files, such as classes, typed data set, text files, and reports. If this folder is not available in the application, you can add this folder.


2 Answers

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.

like image 90
Eilon Avatar answered Oct 02 '22 07:10

Eilon


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.

like image 42
lomaxx Avatar answered Oct 02 '22 07:10

lomaxx