Global.asa use manual

Source: Internet
Author: User
Tags object comments manual include terminates root directory
The Global.asa file is an optional file in which users can specify event scripts and declare objects that have session and application scopes. The contents of the file
Displayed to the user, but is used to store event information and objects that are used globally by the application. The name of the file must be global.asa and must be stored in the application's
The root directory. There can be only one Global.asa file per application.

The Global.asa file can only contain the following:

1. Application Events

2. Session Events

3.<object> statement

TypeLibrary statement
If the included script is not encapsulated with a <SCRIPT> tag, or the defined object has no session or application scope, the server returns an error. The server ignores the marked
Scripts that are recorded but not used by application or session events, and HTML statements in the file.

Scripts contained in Global.asa files can be written in any language that supports scripting. If multiple events use the same scripting language, they can be organized into a set of
<SCRIPT> tags.

When the user saves changes to the Global.asa file, the server finishes processing all the current applications before recompiling the Global.asa file
Please. During this time, the server rejects the other request and returns an error message stating that the application is rebooting and cannot process the request.

When all the user's current requests are processed, the server invokes the Session_OnEnd event for each session, deletes all active sessions, and calls
The Application_OnEnd event closes the application and then compiles the Global.asa file. Next, the user's request launches the application and creates a new session that touches
Hair Application_OnStart and Session_OnStart events.

However, saving changes to the files contained in the Global.asa file does not cause the server to recompile global.asa. In order for the server to identify changes to the containing file,
You must save the Global.asa file again.

A procedure declared in a Global.asa file can only be from one or more of the Application_OnStart, Application_OnEnd, Session_OnStart, and
Session_OnEnd event-related scripts are called. They are not available in ASP pages in an ASP-based application.

To share procedures between applications, you can declare them in a separate file and then use a server-side include (SSI) statement to include the file in the call to the procedure
ASP page. Typically, an extension of the containing file should be. Inc.


An ASP based application consists of all the files in its root directory and its subdirectories. The application starts when a user first opens a Web page in the application,
Terminates when the service is closed. The application has two events, namely the Application_OnStart event and the Application_OnEnd event.

Users can specify scripts for these events in the Global.asa file. When the application starts, the server looks up and processes in the Global.asa file
Application_OnStart event script. When the application terminates, the server processes the Application_OnEnd event script.


1.application_onstart
The Application_OnStart event occurs before the first time a new session (that is, a Session_OnStart event) is created. Only Application and Server built
The object is available. Referencing the session, Request, or Response object in the Application_OnStart event script results in an error.

Grammar
<script language=scriptlanguage runat=server> Sub Application_OnStart ... End Sub

</SCRIPT>

Parameters
ScriptLanguage
Specifies the scripting language used to write event scripts. It can be any language that supports scripting, such as VB script or JScript. If multiple events use the same
Scripting languages, you can organize them under a <SCRIPT> tag.

2.application_onend
The Application_OnEnd event occurs after the application exits after the Session_OnEnd event, and only application and Server-built objects are available.

Grammar
<script language=scriptlanguage runat=server> Sub application_onend ... End Sub

</SCRIPT>

Parameters
ScriptLanguage
Specifies the scripting language used to write event scripts. Can be any language that supports scripting, such as VBScript or JScript. If there are multiple events using the same
A scripting language in which you can organize them under a set of <SCRIPT> tags.
Comments
The MapPath method cannot be invoked in the Application_OnEnd script.




When a user who does not have a session opens a Web page in the application, the Web server automatically creates the session. When the timeout or the server calls the Abandon method, the server
The session will be terminated.

The session has two events, namely the Session_OnStart event and the Session_OnEnd event.

You can specify scripts for both events in the global file Global.asa. When the session starts, the server looks up and processes in the Global.asa file
Session_OnStart event script. The script will be processed before the Web page that the user requests is processed. At the end of the session, the server handles the Session_OnEnd event
Script.

1.session_onstart
The Session_OnStart event occurs when a new session is created by the server. The server processes the requested page before it is executed. The Session_OnStart event is the setting that will
The best time for session variables, because they are set before any pages are accessed. All built-in objects (application, ObjectContext, Request,
Response, Server, and session can be used and referenced in Session_OnStart event scripts.

Grammar
<script language=scriptlanguage runat=server> Sub Session_OnStart ... End Sub

</SCRIPT>

Parameters
ScriptLanguage
Specifies the scripting language used to write event scripts. Can be any language that supports scripting, such as VBScript or JScript. If there are multiple events using the same
A scripting language in which you can organize them under a set of <SCRIPT> tags.
Example
Although the session object persists when the Session_OnStart event contains a Redirect or End method call, the server stops processing
The script in the file that global.asa the file and triggers the Session_OnStart event.

For example, to ensure that a user always starts a session when a particular Web page is opened, you can invoke the Redirect in the Session_OnStart event
Method. When the user enters the application, the server creates a session for the user and processes the Session_OnStart event script. You can include the script in the event
To check that the user opens a page that is not a startup page, and if not, instruct the user to invoke the Response.Redirect method to start the Web page. It is illustrated in the following example.

<script Runat=server language=vbscript>
Sub Session_OnStart
' Make sure ' this new users start on the correct
' Page of the ASP application.

' Replace the ' value given to startpage below
' With the virtual path to your application ' s
' Start page.

StartPage = "/myapp/starthere.asp"
CurrentPage = Request.ServerVariables ("Script_name")

' Do a case-insensitive compare, and if they
' Don ' t match, send the user to the start page.
If StrComp (currentpage,startpage,1) then Response.Redirect (startpage) End IfEnd Sub</script>
The above example runs only in browsers that support cookies. Because browsers that do not support cookies cannot return SessionID cookies, whenever a user requests
When you ask for a Web page, the server creates a new session. Thus, for each request, the server will process the Session_OnStart script and redirect the user to the Kai
Move the page. If you want to use the following script, it is recommended that you put a notice on the startup page telling the user that the site requires a browser that supports cookies.

Comments
Note that any Session_OnStart event scripts after the Redirect method are not executed. Therefore, it should be called at the end of your event script
Redirect method. It is illustrated in the following example.

<script Language=vbscript runat=server>
Sub Session_OnStart
' Session initialization script
Response.Redirect "Http:/server/app/starthere.asp"
End Sub
</SCRIPT>
In the above example, the Redirect method hides all text displayed to the customer during the session initialization script.

2.session_onend
The Session_OnEnd event was discarded or timed out during the session. In a server-built object, only application, server, and session objects are available.

Grammar
<script language=scriptlanguage runat=server> Sub session_onend ... End Sub

</SCRIPT>

Parameters



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.