| ASP.NET Application Phases |
| |
| An Example for Using Global.asax |
| |
| How to add a Global.asax file to the Web Site or Web Application? |
| |
| 1. Click the âWebsite? Menu and then click on âAdd New Item? to open the âAdd New Item? dialog box. |
| |
 |
| |
2. In âAdd New Item? dialog box you will find âGlobal Application Class? item select it and press âAdd? button.
3. To open the âGlobal Application Class? events, select it in the Solution Explorer? and double click it then you will to get all the events of the âGlobal Application Class? as given the figure below. |
| |
 |
| |
| The âGlobal Application Class? events code is are given below: |
| |
| Here first line uses the âApplication? Directive. |
| |
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
}
</script>
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
}
</script> |
| |
|
| |