The Role of the App_Code Folder                                                        

The App_Code folder is used to place source code files which are not directly tied to a specific Web page but
are to be compiled for used by your ASP.NET Web Site. Web Application projects do not use the
App_Code folder because all classes added (no matter what folder) are immediately available to all Web pages.
Files within App_Code are accessible to every page within your Web program. Code within the App_Code
folder will be automatically compiled “on the fly” on an as needed basis – even if the class files were to
change on a already deployed Web server!

The App_Code folder is much like the Bin folder, except that you store source code in it instead of compiled
code. The major benefit of this approach is that it is possible to define custom types for your Web
application without having to compile them independently.

The App_Code folder cannot contain code files from multiple languages. At runtime, the appropriate
compiler kicks in based on the type of files in the folder to automatically generate the assembly needed. If
you would rather have code in multiple languages, however, you can define two or more subdirectories for
holding any number of language-specific managed code files (*.cs, *.vb and so forth). You must also add
<codeSubDirectories> elements to the Web.config file, which lists the language-dedicated subdirectories.

For example, assume you have added an App_Code folder to a Web Site, which contains two subfolders
(MyCSharpCode and MyVbNetCode) that hold language-specific code files.















The next step is to add the <codeSubDirectories> element with the two directories to your Web.confi
g file.


<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings/>
<system.web>
 <compilation debug="false">
   <codeSubDirectories>
     <add directoryName="MyCSharpCode" />
     <add directoryName="MyVbNetCode" />
   </codeSubDirectories>
 </compilation>
 <authentication mode="Windows"/>
</system.web>
</configuration>



Mind you, you needn’t specify what language each folder supports. ASP.NET figures it out automatically.

By doing all this, you won’t get this error:
App_Code Folder
Table of Contents
Copyright (c) 2008.  Intertech, Inc. All Rights Reserved.  This information is to be used exclusively as an
online learning aid.  Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials
Services