Create A Globalasax File

You can insert event handlers to indicate when a user's session starts and ends. For more information about sessions and the Session object, see page 226.

The Session_Start event fires when a new user accesses his or her first ASP page from your ASP.NET application. ASP.NET takes care of the details of determining whether the user is new. When ASP.NET determines that the user is new, the code in the Session_Start event is executed for the user. This code is run before any of the code on the ASP page that was requested. You can use this event for many purposes, including setting variables for the user, redirecting the user to a login page, or using any other code that you want to run when a user first shows up to your Web site.

The Session_End event fires when the user's session times out, which happens when the time between requesting pages is greater than the timeout period set for the application, or when the session is abandoned programmatically. You can use this event to clean up variables created in the Session_Start event or execute any other cleanup code required when users leave your site.

CREATE A GLOBAL.ASAX FILE (CONTINUED)

igj Untitled Notepad_

CREATE A GLOBAL.ASAX FILE (CONTINUED)

igj Untitled Notepad_

| Click 0 to select the folder where you want to store your file.

Type a name for the Web page.

■ You can save the file to the C:\Inetpub\wwwroot\ directory with the filename of Global.asax.

To create the event handler for when the session starts, click between the <SCRIPT> and </SCRIPT> tags, type void Session_Start() {, and press Enter.

le Type } to finish the event handler and press Enter.

| Click 0 to select the folder where you want to store your file.

Type a name for the Web page.

■ You can save the file to the C:\Inetpub\wwwroot\ directory with the filename of Global.asax.

le Click Save to save the Web page.

■ The Default Web site now has a Global.asax file.

To create the event handler for when the session starts, click between the <SCRIPT> and </SCRIPT> tags, type void Session_Start() {, and press Enter.

Press Tab to indent, type the code you want to execute when the application starts, and press Enter.

Note: This code will write a message when the session starts and create a session variable.

le Type } to finish the event handler and press Enter.

Was this article helpful?

0 0

Post a comment