The App_Code Folder
There are a number of new App_NNN folders in
ASP.NET 2.0 with special meaning. One of them is
App_Code.
You might want to have some functionality accessible from many pages in
your application and think of using the Global.asax file or something
similar. Well, there is no Global.asax file by default anymore. You can
add it to your project if you want, but now it uses the <script>
syntax instead of a code-behind file. Besides, when you used it you had
to include an Import directive on every page of your application
referencing the namespace that contain the Global class.
There is another option to have global access to functionality and data
in ASP.NET 2.0, the App_Code folder. This is a productive way of
sharing code between pages of your web application. You can place
source code files (.cs, .vb) in the App_Code folder and they will be
dynamically compiled into an assembly at run time. Any class you put in
the App_Code folder will be made directly accessible from anywhere in
the web application without the need of special references on the code
that uses it.
In VS.NET 2005 if you add a new class from the Add New Item... dialog,
you get a screen asking to put the class into the App_Data folder and
if you answer yes and the folder is not there yet, it gets created.
You can organize the code inside the App_Code folder anyway you like it
but no folder can contain class files of different languages. You don't
need to specify which language you are using, ASP.NET 2.0 will infer it
from the files itself. But, if you want to use more than one language
you have to use different subfolders. You'll need to specify this on
the web.config:
<configuration>
<system.web>
<compilation>
<codeSubDirectories>
<add directoryName="Subfolder1"/>
<add directoryName="Subfolder2"/>
</codeSubDirectories>
</compilation>
</system.web>
</configuration>
This is necessary so ASP.NET treats the different folders as different
compilable units and puts them on different assemblies. Note that there
is no need to actually specify the language. It will still be inferred
from the files.
You can also add other files that would generate a class like .wsdl,
.xsd, etc. and they will also be compiled into assemblies. If the
folder contains files that don't pertain to any programming language in
particular, i.e. all .xsd files, it will use the default compiler for
web applications established in the
<compilation> configuration element.
The Bin Folder
The Bin directory is still there for compiled assemblies, but now it
doesn't get included in the web projects by default anymore. There is
no References special folder either and the web application is not
compiled into a DLL on the Bin folder at least while developing.
The Bin folder is used to throw compiled assemblies and use them
without the need to register them. They are automatically loaded and
accessible. You still need to put some Import directives on pages or
using statements on code-behind classes though, or you'll get some
nasty errors.