Wednesday, February 16, 2011

ASP.NET - Application Anatomy


One of the most remarkable features of the ASP.NET execution model, is the possibility to update the application without the need to restart the server and possible damage to users of the application. This means that adding, changing or removing files in the virtual directory can be done without any impact.
After making a change, the migration process to a new Application Domain is executed. This process executes a safe restart to the application and replaces the files in the temporary directory of ASP.NET.

Directories structure:

  • Bin - Contains all the application libraries (dll's)
  • APP_CODE - Contains all the classes that are dynamically compiled
  • APP_GLOBALRESOURCES - Contains global resources that are used by all application pages
  • APP_LOCALRESOURCES - Contains the resources used by the associated page
  • APP_WEBREFERENCES - Contains web services references
  • APP_DATA - Reserved to Data Storage such as SQL Express databases or xml files.
  • APP_BROWSERS - Contains xml files with browsers definitions, wich allow different renders between browsers
  • APP_THEMES - Contains the application themes


The file Global.asax,  allows you to write code that handles the global events of the application. The file is optional and is just allowed to have one per application and it must be in the root directory.

Application events:
  • Application_BeginRequest - Invoked in each Request
  • Application_EndRequest - Invoked at the end of each Request
  • Application_Start - Invoked when the application start
  • Session_Start - Invoked at the beginning of each session
  • Application_Error - Invoked when a not expected exception is thrown
  • Session_End - Invoked when a user session ends
  • Application_End - Invoked at the end of the application


The configurations of an Asp.Net Application are made in a xml file. There are two types of configuration files, the global ones and the local, and each application can use more than one.

Global Configuration Files:

  • Location: C:\Windows\Microsoft.Net\Framework\[Version]\config
  • All the applications in the server will use that configuration file
Local Configuration Files
  • Location: The application root folder
  • Specific for the application
Config file elements
  •  responsible for the encription of the Asp.Net applications, session cookies and viewstate protection
  • where the connections to external systems are defined, such as database or active directory
  •  where you can define some of your application settings, like the quantity of data you want to retrieve for example
  •  this is one of the most important elements if not the most, and inside it you can set a lot of configurations such as:
    • authentication
    • compilation
    • customErrors
    • Membership
    • pages
    • profile
    • sessionstate
    • trace
There are a few more elements in the configuration file that are not important for this article.

The Page Class

All the Asp.Net pages inherit the base class Page. This is one of the most important classes in Asp.Net.
It contains 3 important properties:

  • Request represents the values and properties of the Http Request that originated the page loading
    • Cookies
    • Headers and ServerVariables
    • IsAuthenticated
    • IsLocal
    • QueryString
  • Response represents the server response to the client
    • Cookies
    • Redirect()
    • Write()
  • Server is a utilities class
    • MachineName
    • GetLastError()
    • HtmlEncode() and HtmlDecode()
    • MapPath()
    • Transfer

This article was translated from

No comments:

Post a Comment