L20 - 5. Web Application States_1(2)

L20 - 5. Web Application States_1(2) - 1 Assignment 5...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Y. Chen 1 Assignment 5 Application Logic Layer 2 * N Services N User Controls 2 * N DLL Library Classes Session State File System Database Data Management Layer Public Page Page with Authentication Page with Authorization Presentation Layer (GUI)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Y. Chen 2 Outline: Structure of ASP.Net Application ASPX files containing Web forms ASCX files containing user controls Web.config files containing configuration settings A Global.asax file containing global application elements DLL (dynamic link library) files containing custom types employed by the application
Background image of page 2
Y. Chen 3 Global.asax File Global.asax is a text file that houses global directives, application-level event handlers, declarations that apply to all parts of the application, and other global application elements. Global directives @ Application directives @ Import directives @ Assembly directives Global event handlers: particularly important and are the main reason why developers include Global.asax files in their applications Global objects (variables)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Y. Chen 4 @ Application Directives in Global.asax @ Application directives serve two purposes: Enable developers to add descriptive text (comments) to applications, and Facilitate code-behind programming in Global.asax files. <% @ Application Description = “MY ASP.NET Application with Global Directives” %> <% @ Import Namespace= “System.Data” %> <script language=“C#” runat=“server”> void Application_Start () { DataSet ds = new DataSet (); ds.ReadXml (Server.MapPath (“GlobalData.xml”)); Application[“GlobalData”] = ds; } </script> This code will be compiled at runtime: Pro: flexibility Con: slow
Background image of page 4
Y. Chen 5 @ Application Directives in Global.asax Write the code as a C# program (.cs) and pre-compile the code as .DLL file, e.g., MyStarter.dll using System.Web; using System.Data; public class MyStarter : HttpApplication { void Application_Start () { DataSet ds = new DataSet (); ds.ReadXml (Server.MapPath (“GlobalData.xml”)); Application[“GlobalData”] = ds; } } <% @ Application inherits = “MyStarter” %> In Global.asax file, use this line to invoke the program
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Y. Chen 6 Global Event Handlers in Global.asax ASP.NET fires global events named Start and End , when an application starts and stops. To process these events, include handlers named Application_Start and Application_End in Global.asax: <script language=“C#” runat= “server”> void Application_Start() { . . . } void Application_End() { Response.Write(“<hr />This page was last accessed at ” + DateTime.Now.ToString()); } </script>
Background image of page 6
Y. Chen Additional Application Events There are many other application events that you can handle by writing your handlers: 7 Event/handler Description Application_Start( ) Called the beginning of the application Application_End( ) Called the end of the application Session_Start( ) Called the beginning of the session Session_End( ) Called the end of the session Application_Error( ) Called when an unhandled error occurs
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Y. Chen
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

L20 - 5. Web Application States_1(2) - 1 Assignment 5...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online