Application Configuration

 
Chapter 14 - ASP.NET Pages
bySimon Robinsonet al.
Wrox Press 2002
  

One thing that has been alluded to throughout this chapter, but without any details being supplied, is the existence of a conceptual application containing web pages and configuration settings. This is an important concept to grasp, especially when configuring your web sites for multiple concurrent users.

A few notes on terminology and application lifetime are necessary here. An application is defined as all files in your project, and is configured by the Web.config file. An Application object is created when an application is started for the first time, which will be when the first HTTP request arrives. Also at this time the Application_Start event is triggered and a pool of HttpApplication instances is created. Each incoming request receives one of these instances, which performs request processing. Note that this means HttpApplication objects do not need to cope with concurrent access, unlike the global Application object. When all HttpApplication instances finish their work the Application_End event fires and the application terminates, destroying the Application object.

The event handlers for the events mentioned above (along with handlers for all other events discussed here) must be defined in the Global.asax file, which contains blanks for you to fill in, for example:

   protected void Application_Start(Object sender, EventArgs e)     {     }   

When an individual user uses the web application a session is started. Similar to the application, this involves the creation of a user-specific Session object, along with the triggering of a Session_Start event. Within a session individual requests trigger Application_BeginRequest and Application_EndRequest events. These may occur several times over the scope of a session as different resources within the application are accessed. Individual sessions may be terminated manually, or will time out if no further requests are received. Session termination triggers a Session_End event and the destruction of the Session object.

With this process in mind, then, how does this help us? Well, there are several things we can do to streamline our application. Consider the example application we have been developing in this chapter. Every time our .aspx page is accessed a recordset is populated with the contents of PCSWebApp3.mdb . This recordset is only ever used for reading data, as the method of inserting events into the database is different. In cases like this we could populate the recordset in the Application_Start event handler and make it available to all users. The only time we would need to refresh the recordset would be if an event were added. This will drastically improve performance with multiple users, as in most requests no DB access will be required.

Another technique we can use is to store session-level information for use by individual users across requests. This might include user-specific information extracted from a data store when the user first connects, and available until the user ceases to submit requests, or explicitly logs out.

We won't detail these techniques here, as this is something better dealt with in specialized ASP.NET books, such as Professional ASP.NET 1.0 (ISBN 1-861007-03-5) but it helps to have a broad understanding of the processes nevertheless. In the next chapter, dealing with Web Services, we will see some of these techniques in action.

  


Professional C#. 2nd Edition
Performance Consulting: A Practical Guide for HR and Learning Professionals
ISBN: 1576754359
EAN: 2147483647
Year: 2002
Pages: 244

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net