Directory Structure in Asp.net

0 comments

ASP.NET directory structure can be determined by the developer's preferences. Apart from a few reserved directory names, the site can span any number of directories.


The structure is typically reflected directly in the urls. Although ASP.NET provides means for intercepting the request at any point during processing, the developer is not forced to funnel requests through a central application or front controller.

The special directory names [from ASP.NET 2.0 on] are:


App_Data Directory

This sub-directory contains the database files. If you are using SQL Server Express, this is where you want to keep the .mdf files. You might have two separate databases and corresponding database files – one for storing your site-application related data (for example: customers, products, orders, partners, etc.), and another for security and user management (this would typically be named ASPNETDB.MDF). You will also have database log files in this directory (for example, aspnetdb_log.ldf, mysite_log.ldf, etc.).
It is more likely that you wouldn’t have this directory at all. Enterprise sites typically have databases running on their own servers and use sophisticated RDBMSs like SQL Server (Enterprise Edition), Oracle, DB/2, etc. In that case, you will have database connection string information in the config file, and no database files in your local directory.


App_Browsers Directory

It is a bit ironic that the need for this directory exists. This directory contains .browser files where you define what you want to show depending on the browser.
In a perfect world, ASP.NET would some how magically make the most appropriate HTML for the browser that’s asking for your page. This works in most of the cases, but one area of problem is mobile browsers. If a person is requesting your image rich and extensive page from their cell phone or PDA, you might not want to say no to that request, but would make up and send an appropriate page for that screen size.


App_Code Directory

Your entire website is not just a bunch of .aspx files for the user interface and .aspx.cs or .aspx.vb files for the code behind those pages. If that’s the case, you will be repeating a whole bunch of code over and over again. For example, your data access layer (the code that deals with database) could be abstracted into a set of ORM (Object-Relational Mapping) classes. There could be a whole bunch of static methods inside a utility class – these methods can be conveniently accessed from all the pages. You want to put the classes that don’t have user interface attached to them in this directory.


Resources Directories

One of the primary uses of resources is to make your web application be appropriately displayed for different languages. If your web application is targeted towards speakers of different languages, the content they generate will be in their own language. For example, a Spanish user using a web-based help desk application will write the details of the issue in Spanish. However, the text of the buttons, links, and other instructions will be in the language it was developed in, most likely, English.
One very expensive way is to develop and maintain different pages for different languages: one set of pages for English, another set for Spanish, yet another set for Japanese, and so on. A better way is to use resource files that contain strings in corresponding language. At runtime ASP.NET will use the strings from the right language resource file; hence there will be only one set of aspx files for all the different languages. Needless to say, this is easier said than done (that’s why large companies have these huge localization and globalization teams). In any case, Visual Studio/ASP.NET provides great infrastructure support for this.
Resource files can also hold images, icons, audio, files, and other content. You can programmatically query for this content at runtime and include it in your pages. One advantage of this would that there won’t be a ton of image files floating around. This approach will be valuable if you want to give just one file, say custom control dll, to the end user (this file will have all the resources like images will be embedded inside).
All the resource files are stored under two directories: App_GlobalResources and App_LocalResources.


Theme Directory

Themes and skins are new features in ASP.NET 2.0. One fundamental difference between styles and themes is that you can apply themes at a global level after the whole web site work has been done. You can let a user customize the look of the entire website (the color scheme, images, styles, etc.) at runtime. Or, you can easily, programmatically set a different look and feel for different users, say a MemberTheme, a PartnerTheme, etc.
Themes consist of several different kinds of files: .skin, .css, images, and resources. They all should ideally reside under Theme directory (though there is some leeway for certain kinds of files).

App_WebReferences 


holds discovery files and WSDL files for references to web services to be consumed in the site.


Bin 


Contains compiled code (.dll files) for controls, components, or other code that you want to reference in your application. Any classes represented by code in the Bin folder are automatically referenced in your application.





0 comments: