Thursday, 2 August 2007

Where is Global.asax file in ASP.NET 2.0

I just figure out how to add Global.asax file in Microsoft Visual Studio.Net 2005.
Here is step by step guide.

First of all you need to Add Global.asax fle from

-->right click project-->Add New Item-->Add Global.asax

change script top tag to

@ Application Language="C#" CodeBehind ="Global.asax.cs" Inherits="NEWSU.Global" %>

where NewsU is namespace in my case \.

comment all script bellow this tag.

Now add normal class file to APP_Code folder in solution.

Right click->Add New Item->Class.

Name it as Global.asax.cs

and then inherit it from System.Web.HttpApplication.

Copy code (events handlers) from Global.asax file to new Global.asax.cs file

aha now you can add your code inside and this class will always execute upon intantiation of application from web server.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// Summary description for Global

namespace NEWSU
public partial class Global : System.Web.HttpApplication
public static int usercnt = 0;
public Global()
// TODO: Add constructor logic here
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

1 comment: