global.asax in ASP.NET 2.0 ???

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
 
T

Teemu Keiski

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top