home *** CD-ROM | disk | FTP | other *** search
-
- <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
-
- <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
-
- <h4>Using the Global.asax File</h4>
-
- <div class="indent" style="font-family:Verdana; font-size:8pt;">
- <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b>
- <a class="toc2" target="content" href="#globalasax">The Global.asax File</a><br>
- <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b>
- <a class="toc2" target="content" href="#events">Application or Session-Scoped Events</a><br>
- <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b>
- <a class="toc2" target="content" href="#staticobjects">Application or Session-Scoped Objects</a><br>
- </div>
-
- <p>
- <hr>
-
- <!--BEGIN SECTION-->
- <a name="globalasasx">
- <span class="subhead">The Global.asax File</span>
- <p>
-
- In addition to writing UI code, developers can also add "application level"
- logic and event handling code into their web applications. This code does not
- handle generating UI - and is typically not invoked in response to individual
- page requests. Instead, it is responsible for handling higher-level application
- events - <b>OnApplicationStart</b>, <b>OnApplicationEnd</b>, <b>OnSessionStart</b>,
- <b>OnSessionEnd</b>, etc. Developers author this logic via a <b>Global.asax</b> file located
- at the root of a particular web application's virtual directory tree.
- ASP+ automatically parses and compiles this file into a dynamic NGWS class
- - that extends the <b>HttpApplication</b> base class - the first time any resource or URL
- within the application namespace is activated or requested.
- <p>
-
- The Global.asax file is parsed and dynamically compiled by ASP+ into a NGWS class
- the first time any resource or URL within its application namespace is activated
- or requested. The Global.asax file itself is configured so that any direct URL
- request for it is automatically rejected (so that external users cannot download
- or view the code written within it).
- <p>
-
-
-
- <!--BEGIN SECTION-->
- <a name="events">
- <span class="subhead">Application or Session-Scoped Events</span>
- <p>
-
- Developers can define handlers for events of the <b>HttpApplication</b> base class by
- authoring methods in the Global.asax file that conform to the naming pattern
- "Application_EventName(AppropriateEventArgumentSignature)". For example:
-
- <div class="code"><pre>
- <script language="C#" runat="server">
-
- public void Application_OnStart()
- {
- // Application startup code goes here
- }
- </script>
- </pre></div>
-
- If the event handling code needs to import additional namespaces, the Import
- directive can be used as follows on a .aspx page:
- <p>
- <div class="code"><pre>
- <%@ Import Namespace="System.Text" %>
- </pre></div>
-
- <p>
- The following sample illustrates the lifetime of the <b>Application</b>,
- <b>Session</b>, and <b>Request</b>.
- <p>
-
- <Acme:SourceRef
- RunSample="/quickstart/aspplus/samples/apps/application1/application1.aspx"
- ViewSource="/quickstart/aspplus/samples/apps/application1.src"
- Icon="/quickstart/aspplus/images/application1.gif"
- Caption="Application1.aspx"
- runat="server" />
-
- <p>
- The first time the page is opened, <b>OnStart</b> is fired for the application and the session:
- <div class="code"><xmp>
- public void Application_OnStart()
- {
- Response.Write("Application is Starting...<br>");
- }
-
- public void Session_OnStart()
- {
- Response.Write("Session is Starting...<br>");
- Session.Timeout = 1;
- }
- </xmp></div>
-
- The <b>BeginRequest</b> and <b>EndRequest</b> events are fired on each request:
- When the page is refreshed, only messages from BeginRequest, EndRequest and
- the <b>Page_Load</b> method will show up. Note that, by abandoning the current
- session (hit the "End this session" button) a new session is created
- and the Session_OnStart event is fired again.
- <p>
-
-
-
- <!--BEGIN SECTION-->
- <a name="staticobjects">
- <span class="subhead">Application or Session-Scoped Objects</span>
- <p>
-
- Static objects - either NGWS classes or classic COM components - can be defined in
- the Global.asax file via the object tag. The scope can be <b>appinstance</b>, <b>session</b> or
- <b>application</b>. The appinstance scope denotes that the object is specific to one
- instance of HttpApplication and is not shared.
-
- <div class="code"><pre>
- <object id="id" runat="server" class="NGWS Class Name" scope="appinstance">
- <object id="id" runat="server" progid="Classic COM ProgID" scope="session"/>
- <object id="id" runat="server" classid="Classic COM ClassID" scope="application"/>
- </pre></div>
-
- <p>
-
- <h4>Section Summary</h4>
- <ol>
- <li>ASP+ applications can define event handlers with application-
- or session-wide scope in the Global.asax file.
- <li>ASP+ applications can define objects with application-
- or session-wide scope in the Global.asax file.
- </ol>
- <p>
-
-
- <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->