. NET ASP Web Application Quick Start (3) (reprint)

Source: Internet
Author: User
Tags root directory
application|web| Quick Start File global.asax

In addition to writing the UI (use Interface: User interface), we can also
Add "Application" level control logic Code and event trigger in application
Order. The code does not operate to generate the UI, and basically does not respond to individual pages please
They are responsible for handling high level application events, including
Application_Start, Application_End, Session_Start and
Session_End. These control logic codes are located in the Web
Application is located in the Global.asax file in the root directory of the virtual directory structure.
Asp. NET resolves this file automatically and compiles it into a dynamic. NET Framework class. This class expands the
HttpApplication base class, when any resource in the application namespace or
When the URL is first accessed, it is created.


The Global.asax file itself is set up, and any direct URL request for it will be automatically
Move rejection, which ensures that external users cannot download it and browse its contents.

Events within the scope of application or session


We can write a method in the Global.asa file to define the HttpApplication base
class, the name of the method to match the string "Application_ event name
Said ". For example, consider the following code written in VB, C #, and JScript three languages:

C#


<script language= "C #" runat= "Server" >

void Application_Start () {
Application startup code goes here
}
</script>

Vb

<script language= "VB" runat= "Server" >

Sub Application_Start ()
' Application startup code goes here
End Sub
</script>

Jscript

<script language= "JScript" runat= "Server" >

function Application_Start (): void {
Application startup code goes here
}
</script>

If the event trigger code needs to enter another namespace, we can edit it in the. aspx page
Write an input ID similar to the following code:

<%@ Import namespace= "System.Text"%>


The following example illustrates the lifetime of application, session, and request:

Application1.aspx


[] Click here to run routines]
| [] View Source code]


When the page is first opened, the application and session OnStart events are activated. About
These event triggers, see the following generations written in VB, C #, and JScript three languages
Code:

C#


void Application_Start () {
Response.Write ("Application is starting ...");
}

void Session_Start () {
Response.Write ("Session is starting ...");
Session.Timeout = 1;
}

Vb

Sub Application_Start ()
Response.Write ("Application is starting ...")
End Sub

Sub session_start ()
Response.Write ("Session is starting ...")
Session.Timeout = 1
End Sub

Jscript

function Application_Start (): void {
Response.Write ("Application is starting ...");
}

function session_start (): void {
Response.Write ("Session is starting ...");
Session.Timeout = 1;
}

The BeginRequest and endrequest events are activated each time a request occurs. Like what
When the page is refreshed, from BeginRequest, endrequest
And the Page_Load method of information will appear. Note that when you discard the current session
(Click the "End" button) to produce a new session, and then again
Triggers the Session_OnStart event.



Related Article

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.