📄 asp_globalasa.asp@output=print
字号:
<h3>
Syntax
</h3>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
<tr valign="top">
<td>
<pre><!--METADATA TYPE="TypeLib"
file="filename"
uuid="typelibraryuuid"
version="versionnumber"
lcid="localeid"
--></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 <script> 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 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. </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
"started",
and the value of the "started" 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><script language="vbscript" runat="server">
sub Session_OnStart
Session("started")=now()
end sub
</script></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 "newpage.asp":
</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
<tr valign="top">
<td>
<pre><script language="vbscript" runat="server">
sub Session_OnStart
Response.Redirect("newpage.asp")
end sub
</script></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 "getcustomers".
The "getcustomers" subroutine opens a database and retrieves a record set from
the "customers" 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><script language="vbscript" runat="server"></pre>
<pre>sub Application_OnStart
getcustomers
end sub</pre>
<pre>sub getcustomers
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=conn.execute("select name from customers")
Application("customers")=rs.GetRows
rs.Close
conn.Close
end sub</pre>
<pre></script></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 "visitors" to 0 when
the server starts</li>
<li>The Session_OnStart subroutine adds one to the variable "visitors" every time a new visitor
arrives</li>
<li>The
Session_OnEnd subroutine subtracts one from "visitors" 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><script language="vbscript" runat="server"></pre>
<pre>Sub Application_OnStart
Application("visitors")=0
End Sub</pre>
<pre>Sub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End Sub</pre>
<pre>Sub Session_OnEnd
Application.Lock
Application("visitors")=Application("visitors")-1
Application.UnLock
End Sub</pre>
<pre></script></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><html>
<head>
</head>
<body>
<p>
There are <%response.write(Application("visitors"))%>
online now!
</p>
</body>
</html></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>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -