Monday, January 3, 2011

usage of Global.axax in asp.net

Following Example will help for maintaining web application

Sample Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Diagnostics;

namespace DemoaboutGloabalasax
{
public class Global : System.Web.HttpApplication
{
// int visTeedCount = 0;
///
/// The Application Started it will fire
/// When the iis Start at the time it will fire
///

///
///
protected void Application_Start(object sender, EventArgs e)
{
EventLog.WriteEntry("Sample Application", "Application Started!", EventLogEntryType.Information);

}

protected void Session_Start(object sender, EventArgs e)
{
//visTedCount = visTedCount + visTedCount;
}

protected void Application_BeginRequest(object sender, EventArgs e)
{

}

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
///need to validate Active Directory User Details here
///
}

///
/// This Event Will fire When the application close
/// Ex: iisreset it will fire
///

///
///
protected void Application_End(object sender, EventArgs e)
{

EventLog.WriteEntry("Sample Application", "Application End at" + DateTime.Now.ToString() + "!", EventLogEntryType.Error);

}
}
}

now You can See all the details about your website in your web server using Event Viewer

1)when the Application Started(iis Started)
2)when the Application Stoped/Restarted(iis Reset)
3)what are the error's occurred in application at what time

No comments: