global.asax in ASP.NET 2.0 ???

  • Thread starter Thread starter Chris Peeters
  • Start date Start date
C

Chris Peeters

Hi,

How do you use a global application class as in ASP.NET 1.0 ?

I try to use the following Global-class but it doesn't work at all:

In Global.asax:
<%@ Application Language="C#" CodeBehind="Global.asax.cs"
Inherits="Global" %>

In Global.asax.cs:

public partial class Global : System.Web.HttpApplication
{
static string LOGFILENAME = @"c:\temp\cslog.txt";

protected void Application_Start(object sender, EventArgs e)
{
StreamWriter sw = new StreamWriter(LOGFILENAME, bAppend);
sw.WriteLine("Application_Start");
sw.Close();
}
}

When starting up, Application_Start() is not invoked at all!
(Know that the code generates no compiler error)

I know that one way to make things work is to put the event handlers in
a <script> - tag directly in Global.asax,
but i want to put the code in a class. it gives more possibillities.

So, just how can you make a global-class work ?

thank you
Chris
 
If you use the stock project model (web site model), you cannot write
code-behind directly to global.asax. Instead you'd declare the class in
App_Code and put the global.asax to inherit from it.

However if you use Web Application Project (Visual Studio 2005 Sp 1 feature
/ add-in project model), then this should work fine.
 
Back
Top