⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asp_globalasa.asp

📁 W3Schools tutorial..web designing
💻 ASP
📖 第 1 页 / 共 2 页
字号:
a call to the TypeLibrary in the Global.asa file, the constants of the COM object can be accessed, and errors can be better reported by the ASP code. If your Web application relies on COM objects that have declared data types in type libraries, you can declare the type libraries in Global.asa.</p>

<h3>
Syntax
</h3>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr valign="top">
    <td>
      <pre>&lt;!--METADATA TYPE=&quot;TypeLib&quot;
file=&quot;filename&quot;
uuid=&quot;typelibraryuuid&quot;
version=&quot;versionnumber&quot;
lcid=&quot;localeid&quot;
--&gt;</pre>
    </td>
  </tr>
</table>
<br />
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3"> 
  <tr>
    <th align="left" valign="top" width="20%">Parameter</th>
    <th align="left" valign="top" width="80%">Description</th>
  </tr>  
  <tr>
    <td valign="top">file</td>
    <td valign="top">Specifies an absolute path to a type library.
      <p>Either the file parameter or the uuid parameter is required</p>
    </td>
  </tr>
  <tr>
    <td valign="top">uuid</td>
    <td valign="top">Specifies a unique identifier for the type library.
      <p>Either the file parameter or the uuid parameter is required</p>
    </td>
  </tr>
  <tr>
    <td valign="top">version</td>
    <td valign="top">Optional. Used for selecting version. If the requested version is not found, then the most recent version is used</td>
  </tr>
  <tr>
    <td valign="top">lcid</td>
    <td valign="top">Optional. The locale identifier to be used for the type library</td>
  </tr>
</table>

<h3>Error Values</h3>

<p>
The server can return one of the following error messages:</p>

<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3"> 
  <tr>
    <th align="left" valign="top" width="20%">Error Code</th>
    <th align="left" valign="top" width="80%">Description</th>
  </tr>  
  <tr>
    <td valign="top">ASP 0222</td>
    <td valign="top"> Invalid type library specification
    </td>
  </tr>
  <tr>
    <td valign="top">ASP 0223</td>
    <td valign="top"> Type library not found
    </td>
  </tr>
  <tr>
    <td valign="top">ASP 0224</td>
    <td valign="top"> Type library cannot be loaded</td>
  </tr>
  <tr>
    <td valign="top">ASP 0225</td>
    <td valign="top"> Type library cannot be wrapped</td>
  </tr>
</table>

<p><b>Note:</b> METADATA tags can appear anywhere in the Global.asa
file (both inside and outside &lt;script&gt; tags). However, it is recommended that
METADATA tags appear near the top of the Global.asa file.
</p>
<hr />

<h2>Restrictions</h2>
<p>Restrictions on what you can include in the Global.asa file:
</p>
<ul>
  <li> You can not display text that is written in the Global.asa file. This file
can't display information</li>
  <li>You can only use Server and Application objects in the Application_OnStart and Application_OnEnd
subroutines. In the&nbsp;Session_OnEnd subroutine, you can use Server, Application, and Session
    objects. In the Session_OnStart subroutine you can use any built-in object</li>
</ul>
<hr />

<h2>How to use the Subroutines</h2>

<p>Global.asa is often used to initialize variables.&nbsp;</p>

<p> The
example below shows how to detect the exact time a visitor first arrives on a Web site. The time is stored in a Session variable named 
&quot;started&quot;,
and the value of the &quot;started&quot; variable can be accessed from any ASP page in the
application:</p>

<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr valign="top">
    <td>
      <pre>&lt;script language=&quot;vbscript&quot; runat=&quot;server&quot;&gt;
sub Session_OnStart
Session(&quot;started&quot;)=now()
end sub
&lt;/script&gt;</pre>
    </td>
  </tr>
</table>

<p>Global.asa can also be used to control page access.
</p>

<p>The example
below shows how to redirect every new visitor to another page, in this case to a
page called &quot;newpage.asp&quot;:
</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr valign="top">
    <td>
      <pre>&lt;script language=&quot;vbscript&quot; runat=&quot;server&quot;&gt;
sub Session_OnStart
Response.Redirect(&quot;newpage.asp&quot;)
end sub
&lt;/script&gt;</pre>
    </td>
  </tr>
</table>
<p>And you can include functions in the Global.asa file.
</p>
<p>In the example below
the Application_OnStart subroutine occurs when the Web server starts. Then
the Application_OnStart subroutine calls another subroutine named &quot;getcustomers&quot;.
The &quot;getcustomers&quot; subroutine opens a database and retrieves a record set from
the &quot;customers&quot; table. The record set is assigned to an array, where it
can be accessed from any ASP page without querying the database:
</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr valign="top">
    <td>
      <pre>&lt;script language=&quot;vbscript&quot; runat=&quot;server&quot;&gt;</pre>
      <pre>sub Application_OnStart
getcustomers
end sub</pre>
      <pre>sub getcustomers&nbsp;
set conn=Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Provider=&quot;Microsoft.Jet.OLEDB.4.0&quot;
conn.Open &quot;c:/webdata/northwind.mdb&quot;
set rs=conn.execute(&quot;select name from customers&quot;)
Application(&quot;customers&quot;)=rs.GetRows
rs.Close
conn.Close
end sub</pre>
      <pre>&lt;/script&gt;</pre>
    </td>
  </tr>
</table>
<br />
<hr />
<h2>Global.asa Example
</h2>
<p>In this example we will create a Global.asa file that counts the number of
current visitors.
</p>
<ul>
  <li>The Application_OnStart sets the Application variable &quot;visitors&quot; to 0 when
    the server starts</li>
  <li>The Session_OnStart subroutine adds one to the variable &quot;visitors&quot; every time a new visitor
    arrives</li>
  <li>The
Session_OnEnd subroutine subtracts one from &quot;visitors&quot; each time this subroutine is
    triggered</li>
</ul>
<p>The Global.asa file:
</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr valign="top">
    <td>
      <pre>&lt;script language=&quot;vbscript&quot; runat=&quot;server&quot;&gt;</pre>
      <pre>Sub Application_OnStart
Application(&quot;visitors&quot;)=0
End Sub</pre>
      <pre>Sub Session_OnStart
Application.Lock
Application(&quot;visitors&quot;)=Application(&quot;visitors&quot;)+1
Application.UnLock
End Sub</pre>
      <pre>Sub Session_OnEnd
Application.Lock
Application(&quot;visitors&quot;)=Application(&quot;visitors&quot;)-1
Application.UnLock
End Sub</pre>
      <pre>&lt;/script&gt;</pre>
    </td>
  </tr>
</table>
<p>To display the number of current visitors in an ASP file:
</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr valign="top">
    <td>
      <pre>&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;
There are &lt;%response.write(Application(&quot;visitors&quot;))%&gt;
online now!
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
    </td>
  </tr>
</table>
<br />
<hr />
<a href="asp_incfiles.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="asp_send_email.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>

<br />
<hr />

<!-- **** SPOTLIGHTS 1 **** -->

<iframe src="../banners/aspallframe.asp" height="110" width="485"
marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
Your browser does not support inline frames or is currently configured not to display inline frames.
</iframe>
<hr />
<!-- **** SPOTLIGHTS 2 **** -->


<!-- **** SPOTLIGHTS 3 **** -->
<table cellpadding="0" cellspacing="0"><tr><td width="72"></td><td>
<script type="text/javascript"><!--
google_ad_client = "pub-3440800076797949";
/*txt*/
google_ad_slot = "1699448869";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="../../pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr></table>
<hr />

<center>

<iframe style="background-color:#ffffff" src="../banners/aspallbannerframe.asp" height="60" width="468" marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
Your browser does not support inline frames or is currently configured not to display inline frames.
</iframe>

</center>
<hr />

<table>
<tr>
<td><img src="../images/diploma.jpg" alt="diploma" /></td>
<td>&nbsp;&nbsp;</td>
<td valign="top">
<h2>Get Your Diploma!</h2>
<p>W3Schools' Online Certification Program is the perfect solution for busy 
professionals who need to balance work, family, and career building.</p>
<p>The <a href="../cert/default.asp">HTML Certificate</a> is for developers who want to document their knowledge of HTML, XHTML, and CSS.</p>
<p>The <a href="../cert/default.asp">ASP Certificate</a> is for developers who want to document their knowledge of ASP, SQL, and ADO.</p>
</td>
</tr>
</table>
<br />


<hr />

<!-- **** END SPOTLIGHTS **** -->

</td></tr>

<tr><td>
<p>Jump to: <a href="#top" target="_top"><b>Top of Page</b></a>
or <a href="../default.asp" target="_top"><b>HOME</b></a> or
<a href='asp_globalasa.asp@output=print' target="_blank">
<img src="../images/print.gif" alt="Printer Friendly" border="0" />
<b>Printer friendly page</b></a></p>
<p>W3Schools provides material for training only. We do not warrant the correctness of its contents.
The risk from using it lies entirely with the user.
While using this site, you agree to have read and accepted our
<a href="../about/about_copyright.asp">terms of use</a> and
<a href="../about/about_privacy.asp">privacy policy</a>.
</p>
<p><a href="../about/about_copyright.asp">Copyright 1999-2008</a> by Refsnes Data. All Rights Reserved.</p>
<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr>
<td width="60%" align="left">
<a href="../../validator.w3.org/check@uri=referer" target="_blank">
<img src="../images/vxhtml.gif" alt="Validate" width="88" height="31" border="0" /></a>
<a href="../../jigsaw.w3.org/css-validator/check@uri=referer" target="_blank">
<img src="../images/vcss.gif" alt="Validate" width="88" height="31" border="0" /></a>
<a href="../../www.w3.org/WAI/WCAG1A-Conformance" title="Explanation of Level A Conformance" target="_blank">
<img src="../images/wai.gif" alt="W3C-WAI level A conformance icon" width="88" height="31" border="0" /></a>
</td>
<td>
<a href="../xhtml/xhtml_howto.asp" target="_top">W3Schools was converted to XHTML in December 1999</a>
</td></tr>

</table>
</td></tr>
</table>
</td>


<td width="145" align="center" valign="top">




<iframe style="background-color:#f1f1f1" src="../banners/rightcolumn.asp@secid=asp" height="1850" width="147"
marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
</iframe>

</td>
</tr></table>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -