home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / doc / globalasax.aspx < prev    next >
Encoding:
Text File  |  2000-06-08  |  4.9 KB  |  136 lines

  1.  
  2. <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
  3.  
  4. <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
  5.  
  6. <h4>Using the Global.asax File</h4>
  7.  
  8. <div class="indent" style="font-family:Verdana; font-size:8pt;">
  9.     <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  10.     <a class="toc2" target="content" href="#globalasax">The Global.asax File</a><br>
  11.     <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  12.     <a class="toc2" target="content" href="#events">Application or Session-Scoped Events</a><br>
  13.     <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  14.     <a class="toc2" target="content" href="#staticobjects">Application or Session-Scoped Objects</a><br>
  15. </div>
  16.  
  17. <p>
  18. <hr>
  19.  
  20. <!--BEGIN SECTION-->
  21. <a name="globalasasx">
  22. <span class="subhead">The Global.asax File</span>
  23. <p>
  24.  
  25. In addition to writing UI code, developers can also add "application level" 
  26. logic and event handling code into their web applications. This code does not
  27. handle generating UI - and is typically not invoked in response to individual 
  28. page requests.  Instead, it is responsible for handling higher-level application 
  29. events - <b>OnApplicationStart</b>, <b>OnApplicationEnd</b>, <b>OnSessionStart</b>, 
  30. <b>OnSessionEnd</b>, etc.  Developers author this logic via a <b>Global.asax</b> file located
  31. at the root of a particular web application's virtual directory tree. 
  32. ASP+ automatically parses and compiles this file into a dynamic NGWS class 
  33. - that extends the <b>HttpApplication</b> base class - the first time any resource or URL
  34. within the application namespace is activated or requested.
  35. <p>
  36.  
  37. The Global.asax file is parsed and dynamically compiled by ASP+ into a NGWS class 
  38. the first time any resource or URL within its application namespace is activated
  39. or requested. The Global.asax file itself is configured so that any direct URL
  40. request for it is automatically rejected (so that external users cannot download 
  41. or view the code written within it).
  42. <p>
  43.  
  44.  
  45.  
  46. <!--BEGIN SECTION-->
  47. <a name="events">
  48. <span class="subhead">Application or Session-Scoped Events</span>
  49. <p>
  50.  
  51. Developers can define handlers for events of the <b>HttpApplication</b> base class by
  52. authoring methods in the Global.asax file that conform to the naming pattern
  53. "Application_EventName(AppropriateEventArgumentSignature)". For example:
  54.  
  55. <div class="code"><pre>
  56. <script language="C#" runat="server">
  57.  
  58. public void Application_OnStart() 
  59. {
  60.   // Application startup code goes here  
  61. }
  62. </script>
  63. </pre></div>
  64.  
  65. If the event handling code needs to import additional namespaces, the Import 
  66. directive can be used as follows on a .aspx page:
  67. <p>
  68. <div class="code"><pre>
  69. <%@ Import Namespace="System.Text" %>
  70. </pre></div>
  71.  
  72. <p>
  73. The following sample illustrates the lifetime of the <b>Application</b>, 
  74. <b>Session</b>, and <b>Request</b>.
  75. <p>
  76.  
  77. <Acme:SourceRef 
  78.   RunSample="/quickstart/aspplus/samples/apps/application1/application1.aspx" 
  79.   ViewSource="/quickstart/aspplus/samples/apps/application1.src"
  80.   Icon="/quickstart/aspplus/images/application1.gif"
  81.   Caption="Application1.aspx"
  82.   runat="server" />
  83.  
  84. <p>
  85. The first time the page is opened, <b>OnStart</b> is fired for the application and the session:
  86. <div class="code"><xmp>
  87. public void Application_OnStart() 
  88. {
  89.   Response.Write("Application is Starting...<br>");
  90. }
  91.  
  92. public void Session_OnStart() 
  93. {
  94.   Response.Write("Session is Starting...<br>");
  95.   Session.Timeout = 1;
  96. }
  97. </xmp></div>
  98.  
  99. The <b>BeginRequest</b> and <b>EndRequest</b> events are fired on each request:
  100. When the page is refreshed, only messages from BeginRequest, EndRequest and
  101. the <b>Page_Load</b> method will show up. Note that, by abandoning the current
  102. session (hit the "End this session" button) a new session is created
  103. and the Session_OnStart event is fired again.
  104. <p>
  105.  
  106.  
  107.  
  108. <!--BEGIN SECTION-->
  109. <a name="staticobjects">
  110. <span class="subhead">Application or Session-Scoped Objects</span>
  111. <p>
  112.  
  113. Static objects - either NGWS classes or classic COM components - can be defined in
  114. the Global.asax file via the object tag. The scope can be <b>appinstance</b>, <b>session</b> or 
  115. <b>application</b>. The appinstance scope denotes that the object is specific to one
  116. instance of HttpApplication and is not shared.
  117.  
  118. <div class="code"><pre>
  119. <object id="id" runat="server" class="NGWS Class Name" scope="appinstance">
  120. <object id="id" runat="server" progid="Classic COM ProgID" scope="session"/>
  121. <object id="id" runat="server" classid="Classic COM ClassID" scope="application"/>
  122. </pre></div>
  123.  
  124. <p>
  125.  
  126. <h4>Section Summary</h4>
  127. <ol>
  128. <li>ASP+ applications can define event handlers with application- 
  129. or session-wide scope in the Global.asax file.
  130. <li>ASP+ applications can define objects with application- 
  131. or session-wide scope in the Global.asax file.
  132. </ol>
  133. <p>
  134.  
  135.  
  136. <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->