Aspnet Applications And State Management

Kxtl O. If you want to track statistics on your site, you can log information from Global.asax to a file.

Example:

<% @ Import Namespace="System.IO" %>

<SCRIPT LANGUAGE="C#" RUNAT="Server">

void Application_Start() {

FileStream filestreamLog = new FileStream("applogging.txt", FileMode.Append,

FileAccess.Write ); StreamWriter streamwriterLog = new StreamWriter(filestreamLog);

streamwriterLog.WriteLine("{0}", String.Concat("The application started at"

,DateTime.Now)); streamwriterLog.Close(); streamwriterLog.Close();

Save the file.

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

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

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

Save the file.

■ This example is saving the Global.asax to the default Web site.

Request an ASP.NET Web page from the default Web site.

■ The message about the session event handler appears.

Note: You can request any ASP.NET Web page in the default Web site. In the example, the Comments.aspx ASP.NET Web page is requested.

USING

Was this article helpful?

0 0

Post a comment