home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / doc / applications.aspx < prev    next >
Encoding:
Text File  |  2000-06-09  |  6.0 KB  |  160 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>Application Overview</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="#what">What is an ASP+ Application ?</a><br>
  11.     <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  12.     <a class="toc2" target="content" href="#creating">Creating an Application</a><br>
  13.     <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  14.     <a class="toc2" target="content" href="#lifetime">Lifetime of an Application</a><br>
  15.     <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  16.     <a class="toc2" target="content" href="#multiplethreads">A Note on Multiple Threads</a><br>
  17. </div>
  18.  
  19. <p>
  20. <hr>
  21.  
  22. <!--BEGIN SECTION-->
  23. <a name="what">
  24. <span class="subhead">What is an ASP+ Application ?</span>
  25. <p>
  26.  
  27.  
  28. ASP+ defines an application as the sum of all files, pages, handlers, modules 
  29. and executable code that can be invoked or run in the scope of a given virtual 
  30. directory (and its subdirectories) on a web application server.  For example, 
  31. an "order" application might be published via the "/order" virtual directory on a 
  32. web server computer. For IIS the virtual directory can be set up via the Internet
  33. Services Manager and contains all subdirectories, unless they are virtual directories
  34. themselves.
  35. <p>
  36.  
  37.  
  38. Each ASP+ application on a web server is executed within a unique NGWS runtime 
  39. <b>Application Domain</b> - guaranteeing class isolation (no versioning/naming conflicts),
  40. security sandboxing (preventing access to certain machine/network resources), 
  41. and static variable isolation.
  42. <p>
  43.  
  44. ASP+ maintains a pool of HttpApplication instances over the course of a web 
  45. application's lifetime. ASP+ automatically assigns one of these instances to
  46. process each incoming HTTP request that is received by the application.  
  47. The particular HttpApplication instance assigned is responsible for managing
  48. the entire lifetime of the request, and is only re-used after the request has
  49. been completed. This means that user code within it does not need to be 
  50. re-entrant.
  51. <p>
  52.  
  53.  
  54.  
  55. <!--BEGIN SECTION-->
  56. <a name="creating">
  57. <span class="subhead">Creating an Application</span>
  58. <p>
  59.  
  60. To create an ASP+ application you can use an existing virtual directory or 
  61. create a new one. For example, if you installed Windows 2000 Server including 
  62. IIS, you probably have a directory C:\InetPub\WWWRoot. You can configure IIS
  63. using the Internet Services Manager, available under 
  64. Start <nobr>-></nobr> Programs <nobr>-></nobr> Administrative Tools. 
  65. Right-Click on an existing directory and choose either New (to create a new
  66. virtual directory) or Properties (to promote an existing regular directory).
  67. <p>
  68.  
  69. By placing a simple .aspx page like the following in the virtual directory and hitting it with the browser, you trigger
  70. the creation of the ASP+ application.
  71.  
  72. <div class="code"><pre>
  73. <%@Page Language="C#"%>
  74. <html>
  75. <body>
  76. <h1>hello world, <% Response.Write(DateTime.Now.ToString()); %></h1>
  77. </body>
  78. </html>
  79. </pre></div>
  80.  
  81. Now you can add appropriate code to use
  82. the <a href="stateoverview.aspx">Application</a> object, for example to store
  83. objects with application scope. By creating a 
  84. <a href="globalasax.aspx">global.asax</a> file you can define various event handlers,
  85. e.g. for the Application_OnStart event.
  86. <p>
  87.  
  88. <!--BEGIN SECTION-->
  89. <a name="lifetime">
  90. <span class="subhead">Lifetime of an Application</span>
  91. <p>
  92.  
  93. An ASP+ application is created the first time a request is made to the server, before
  94. that no ASP+ code is executing. Upon receiving the first request, a pool of HttpApplication
  95. instances is created, and the Application_OnStart event is fired. The HttpApplication 
  96. instances process this and subsequent requests, until the last instance exits and the 
  97. Application_OnEnd event is fired.
  98. <p>
  99.  
  100. Note, that the Init and Dispose methods of HttpApplication are called per instance and
  101. thus can be called several times between Application_OnStart and Application_OnEnd. Only
  102. these events are shared among all instances of HttpApplication in one ASP+ 
  103. application.
  104. <p>
  105.  
  106.  
  107.  
  108. <!--BEGIN SECTION-->
  109. <a name="multiplethreads">
  110. <span class="subhead">A Note on Multiple Threads</span>
  111. <p>
  112.  
  113. If you use objects with application scope, you should be aware that
  114. ASP+ processes requests concurrently and the Application object can be 
  115. accessed by multiple threads. So the following code is dangerous and will probably
  116. not produce the expected result, if the page is requested several times from
  117. different clients at the same time:
  118.  
  119. <div class="code"><pre>
  120. <%
  121. Application["counter"] = (Int32)Application["counter"] + 1;
  122. %>
  123. </pre></div>
  124.  
  125. To make code thread-safe, the access of the Application object can be serialized 
  126. via the Lock and UnLock methods. This of course means accepting a considerable 
  127. performance hit:
  128. <div class="code"><pre>
  129. <%
  130. Application.Lock();
  131. Application["counter"] = (Int32)Application["counter"] + 1;
  132. Application.UnLock();
  133. %>
  134. </pre></div>
  135.  
  136. Another solution is to make the object itself stored with application scope
  137. thread-safe. Note, that for example the collection classes in the System.Collections namespace
  138. are not thread-safe for performance reasons.
  139. <p>
  140.  
  141. <h4>Section Summary</h4>
  142. <ol>
  143. <li>ASP+ applications consist of everything living under one virtual directory of the web server.
  144. <li>Create an ASP+ application by adding files to a virtual directory on the web server.
  145. <li>The lifetime of an ASP+ application is marked by Application_OnStart and Application_OnEnd.
  146. <li>Access of application-scope objects must be safe for multi-threaded access.
  147. </ol>
  148. <p>
  149.  
  150.  
  151. <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.