ASP The Global.asa file
The Global.asa file
The Global.asa record is a discretionary document that can contain statements of items, factors, and strategies that can be gotten to by each page in an ASP application.
The Global.asa record can contain just the following:
- Application events
- Session events
- <object> declarations
- TypeLibrary declarations
- the #include directive
Note: The Global.asa record must be put away in the root index of the ASP application, and every application can just have one Global.asa file.
Events in Global.asa
In Global.asa you can instruct the application and session objects when the application/session begins and what to do when the application/session closes. The code for this is put in occasion handlers. The Global.asa record can contain four sorts of events:Application_OnStart - Occurs when the FIRST client calls the principal page in an ASP application. This occasion happens after the Web server is restarted or after the Global.asa record is altered. The "Session_OnStart" occasion happens following this occasion.
Session_OnStart - This occasion happens EVERY time a NEW client asks for his or her first page in the ASP application.
Session_OnEnd - This occasion happens EVERY time a client closes a session. A client session finishes after a page has not been asked for by the client for a determined time (as a matter of course this is 20 minutes).
Application_OnEnd - This occasion happens after the LAST client has finished the session. Commonly, this occasion happens when a Web server stops. This technique is utilized to tidy up settings after the Application stops, as erase records or compose data to content files.
A Global.asa record could look something like this:
Note: Because we can't utilize the ASP content delimiters (<% and %>) to embed contents in the Global.asa document, we put subroutines inside a HTML <script> element.
It is conceivable to make objects with session or application scope in Global.asa by utilizing the <object> tag.
Note: The <object> tag ought to be outside the <script> tag!
|scope||Sets the extent of the article (either Session or Application)|
|id||Specifies an extraordinary id for the object|
|ProgID||An id related with a class id. The configuration for ProgID is [Vendor.]Component[.Version]
Either ProgID or ClassID must be specified.
|ClassID||Specifies a one of a kind id for a COM class object.
Either ProgID or ClassID must be specified.
The first precedent makes an object of session scope named "MyAd" by utilizing the ProgID parameter:
The second precedent makes an object of use scope named "MyConnection" by utilizing the ClassID parameter:
The objects pronounced in the Global.asa record can be utilized by any content in the application:
<object runat="server" scope="session" id="MyAd" progid="MSWC.AdRotator">
You could reference the item "MyAd" from any page in the ASP application:
A few .ASP FILE:
A TypeLibrary is a holder for the substance of a DLL document relating to a COM object. By including a call to the TypeLibrary in the Global.asa document, the constants of the COM article can be gotten to, and blunders can be better announced by the ASP code. In the event that your Web application depends on COM objects that have announced information types in sort libraries, you can pronounce the sort libraries in Global.asa.
file="filename" uuid="id" version="number" lcid="localeid"
|file||Specifies a flat out way to a sort library.
Either the document parameter or the uuid parameter is required
|uuid||Specifies a one of a kind identifier for the sort library.
Either the record parameter or the uuid parameter is required
|version||Optional. Utilized for choosing rendition. On the off chance that the asked for variant isn't discovered, at that point the latest adaptation is used|
|lcid||Optional. The region identifier to be utilized for the sort library|
The server can return one of the accompanying blunder messages:
|ASP 0222||Invalid sort library specification|
|ASP 0223||Type library not found|
|ASP 0224||Type library can't be loaded|
|ASP 0225||Type library can't be wrapped|
Note: METADATA labels can show up anyplace in the Global.asa record (both inside and outside <script> labels). Be that as it may, it is prescribed that METADATA labels show up close to the highest point of the Global.asa file.
Restrictions on what you can incorporate into the Global.asa file:
- You can't show content written in the Global.asa record. This document can't show information
- You can just utilize Server and Application questions in the Application_OnStart and Application_OnEnd subroutines. In the Session_OnEnd subroutine, you can utilize Server, Application, and Session objects. In the Session_OnStart subroutine you can utilize any implicit object
How to utilize the Subroutines
Global.asa is frequently used to instate variables.
The precedent beneath tells the best way to distinguish the specific time a guest initially touches base on a Web webpage. The time is put away in a Session variable named "started", and the estimation of the "started" variable can be gotten to from any ASP page in the application:
Global.asa can likewise be utilized to control page access.
The precedent beneath tells the best way to divert each new guest to another page, for this situation to a page called "newpage.asp":
And you can incorporate capacities in the Global.asa file.
In the model beneath the Application_OnStart subroutine happens when the Web server begins. At that point the Application_OnStart subroutine calls another subroutine named "getcustomers". The "getcustomers" subroutine opens a database and recovers a record set from the "customers" table. The record set is alloted to a cluster, where it can be gotten to from any ASP page without questioning the database:
set rs=conn.execute("select name from customers")