App_Code Folder
As its name suggests, the App_Code Folder stores classes, typed data sets, etc. All the items that are stored inApp_Code are automatically accessible throughout the application. If we store any class files (like .cs or .vb) it compiles them automatically. It automatically creates type data sets from .xsd (XML schema) files, and creates XML web service proxy classes from WSDL.Let's have a look at how we can use the App_Code folder.
We can add an App_Code folder, by Solution File → right click → Add ASP.NET Folder → App_Code. The App_Codefolder is now added to your application.
Note: Try to add one more App_Code folder by using the same steps. Oops... the App_Code folder is no longer available there. So, ASP.NET allows you to add an App_Code folder only once.
Now we can add new items like classes, text and xml files into the App_Code folder and we can also add existing files there.
Let's have a look at one example that shows how it works. Into the App_Code folder, I have added a classMyCSharpClass.cs.
In that class I have written a small spice of code for adding two numbers.
Now, Try to access this class, from any where in your application. You will see that
MyCSharpClass
is accessiblethroughout the application.
If we want to store different classes like .cs or .vb, then what will happen? If we kept both .cs and .vb classes in the same folder, it will give following compilation error:
This is because all the classes contained in the App_Code folder are built into a single assembly and it can't have different languages at root level, or even at child level folders in following manner:
We have a solution to overcome this problem. We have to create separate folders for C# and for VB or other classes.
Store class files separately in those folders and an configure the folder hierarchy in the web.config file.
Now I will move to our next part -the Bin folder.
Bin Folder
The Bin folder is used for keeping assemblies inside it. We can access those as a reference from anywhere of our web application. Use of Bin folder comes into the picture if we use any class library within our web application. Suppose we are creating a class library called
TestLib
. After building the library, we will get TestLib.dll. Now, right click on solution file → Add References → Project, select the TestLib
Project, click on OK. Check the Bin folder, it will containTestLib.dll and TestLib.pdb files.
Assemblies in the Bin folder do not need to registered on the system, ASP.NET recognizes the presence of DLLs inside the Bin Folder. Keeping .pdb files inside Bin folder helps us in debugging. The main limitation of storing assemblies in the Bin folder is that their scope is limited to the current application. Therefore, they cannot access any code outside of current web application. [Source]
Next, let's have a look at App_Data folder
App_Data Folder
The App_Data folder is used as a
data storage for the web application. It can store files such as .mdf, .mdb, and XML. It manages all of your application's data centrally. It is accessible from anywhere in your web application.The real advantage of the App_Data folder is that, any file you place there won't be downloadable.
We can add .mdf files to the App_Data folder directly by selecting Add New Item. From there we can a create table, procedure or function without opening SQL Server.Now if we want to add that data to our application, we can easily use it.
Now, look at the connection string that we need to write for accessing the App_Data folder's databases.
We can connect with MyDB.mdf database using this connection string. Check the example below, which I have used to read the table data from the MyDB.Mdf file
.
App_Theme Folder
If you want to give your web sites a consistent look, then you need to design themes for your web application. TheApp_Themes folder contains all such themes. An App_Theme folder can contain two subfolders; one for CSS files and the other for skin files. When we add an App_Theme folder, a subfolder with name Theme1 will be automatically created. We can change the name of the theme folder as per our requirements.
I will not cover how to create skin files or CSS file in this article, my main concern here is how to apply them. You can easily find the details ofskins and CSS via Google.
Now that we have to apply the theme to the page, there are several way to do that. We could set the theme fromaspx page using a page directive in following way:
While we are going to set themefrom aspx page, the list of themes available to us is as shown in the figure. We can set the theme from the code behind file also, and we can even change theme at runtime (using
HttpHandler
).App_Browser Folder
The App_Browser folder contains browser information files (.browser files). These files are XML based files which are used to identify the browser and browser capabilities. You will find the browser files in the following location:
If you want to change a .browser file, just copy the file to the App_Browser folder and change it. You can create new browser files by just clicking on Add New Item of the App_Browser folder
As I already mentioned, a browser file is a configuration file, it generally looks like this:
App_WebReference Folder
As the name suggests, the App_WebReference folder contain references to any web services. If we added any web services with our web application, they go automatically into the App_WebReference folder, in the same way as in windows applications, if we added any DLLs, they would go under the Reference folder.