Understanding ASP.NET Application Folders
 
Published: 12 Mar 2007
Abstract
This article describes the defined application folder structure in ASP.NET 2.0.
by SANJIT SIL
Feedback
Average Rating: 
Views (Total / Last 10 Days): 58368/ 73

Introduction

We can add any number of files and folders within the application without recompiling each and every time a new file is added to the overall solution. ASP.NET2.0 has the capability to automatically precompile ASP.NET application dynamically. In case of ASP.NET 1.0 or ASP.NET 1.1 everything is complied in our solution into a DLL. Now this is not required in ASP.NET 2.0 because of its defined folder structure. This article will define each of these folders and how they work. The sample code snippets have been written in C#. Let us now examine the usage of each folder in detail.

App_Code

The App_Code folder is meant to store classes, .wsdl files, and typed datasets. Any of these items stored in this folder then is automatically available to all the pages in the solution. To create an APP_Code Folder, we can follow some steps. Right click on solution -> Select Add Folder -> App_Code Folder. After adding App_Code Folder, we can add files on it. Right Click on App_Code Folder will give the option to add different types of files which include class file, text file, dataset, report and class diagram. Let us add a class file named test.cs.

Listing 1

public class CurrentDateTime()
public string showDateTime()
{
return  System.DateTime.Now.ToString();
}

Now the class test.css is available to all the pages in the solution. To test the same an aspx page is created named test.aspx.

Listing 2

protected void Page_Load(object sender, EventArgs e)
    {
        CurrentDateTime cDT=new CurrentDateTime();
        string cTime = cDT.showDateTime();
        Response.Write(cTime.ToString());
    }

When we run test.aspx page, we will see that it uses the test.css class. So we do not need to compile the class file before it is in use. It should be noted that whatever we place in the App_Code Folder, would be complied into a single assembly. A class file written in C# can be used by the pages written in a different language (say in Visual Basic 2005). Even we can have class files written in different languages, but to work with them we have to configure in the following ways: We should add two different folders in App_Code Folder to place C# class and VB class separately. After that we should do required modification in web.config file.

Listing 3

<compilation>
<codeSubDirectories>
<add directoryName=”VBFolder”></add>
<add directoryName=”CSFolder”></add>
</compilation>

So it is important that the language specific subdirectory is registered in the web.config file; otherwise, all files underneath App_Code folder will be complied to a single assembly regardless of the folder they belong to. If a directory mentioned in the <codeSubDirectories> section does not exist, compilation error will arise.

App_Themes

Themes are used to define visual styles for web pages. Themes are made up of a set of elements: skins, Cascading Style Sheets (CSS), images, and other resources. Themes can be applied at the application, page, or server control level. By storing these elements within the App_Themes Folder all the pages (including controls in page) in the solution, we take advantage of Theme. For more on Themes you can read my article "Working with Themes in ASP.NET 2.0."

App_Data

It Contains application data stored in the form of files including MDF files, XML files, text file as well as other data store files. The user account utilized by the application will have read and write access to any of the files contained within the App_Data Folder. By default, this is the ASPNET account. The default ASPNET account is granted full permissions on the folder. If we change the ASPNET account, we have to make sure that the new account is granted read/write permissions on the folder. Various ASPNET application features, such as the providers for membership and roles, as well as the Web Site Administration Tool, are configured to work with the App_Data folder specifically.

Note: As a security measure, files in the App_Data folder are not served by the Web server. Do not store any Web pages in the App_Data folder because users will see an error if they request a page from that folder.

App_GlobalResources

In general, a resource file is nonexecutable text associated with the program. Typical resources are images, icon, text and auxiliary files. Application resources are stored outside of the application so that they can be recompiled and replaced without affecting and recompiling the application itself. It is like the App_LocalResources folders, but contains .resx files that are not bound to a specific page. Resource values in .resx files in the App_GlobalResource folders can be accessed programmatically from application code. You can add Assembly Resource Files (.resx) to this folder and they are dynamically compiled and made part of the solution for use by all your aspx pages in the application. Let us assume that we have created two resource files in this folder, Resource.resx and Resource.it.resx. The first file, Resource.resx, is the default language file using American English. The second file is for same text but for Italian language. If anyone invokes any page after setting browser culture Italian, then the information will come from Resource.it.resx file and for others the information will come from default Resource.resx file.

App_LocalResources

We can add resource files that are page-specific to the \App_LocalResources folder. We can define multiple .resx files for each page, each .resx file representing a different language or language/culture combination.

App_WebReferences

The App_WebReferences folder is a new name for the previous Web References folder used in previous versions of ASP.NET. Now you can use the \App_WebReferences folder and have automatic access to the remote Web services referenced from your application.

App_Browsers

The App_Browsers folder holds browser files, which are XML files used to describe characteristics and capabilities of these browsers. We can find a list of globally accessible browser files in the CONFIG\Browsers folder under the installation path. In addition, if you want to change any part of these default browser definition files, just copy the appropriate browser file from the Browsers folder to your application’s \App_Browsers folder and change the definition.

Bin

It contains compiled assemblies (.DLL files) for controls, components, or other code that we want to reference in our application. Any DLL files found in the directory will be automatically linked in the application. This is also recognized by ASP.NET 1.x applications. This folder is mandatory.

References

Conclusion

ASP.NET 2.0 introduces a number of special directories for application resources. These directories live as subfolders in the application root. Visual Web Developer does not create these folders by default, except the App_Data folder. In some cases, the folders are created by utilities. For example, running the Generate Local Resource command creates the App_LocalResources folder. In other cases, we can create the folders manually.



User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 5:15:33 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search