gilles27
gilles27

Reputation: 2241

Why are the Global.asax events not firing in my ASP .NET website?

I've been developing an ASP .NET 3.5 web application against Cassini, the built-in web development server, rather than against IIS.

In my Global.asax file, in the Application_Start event handler, I have some code which logs the fact that the website has started up. This all works fine with Cassini.

Since deploying the site to a virtual directory on a test server using IIS6, I am finding there are no log entries being written, and so I'm concluding that the Application_Start handler is not firing.

I then tried removing the virtual directory and running the site directly out of the root of the website on the test server, but it didn't make any difference - still no log entry for application start.

I know these events should fire irrespective of my deployment environment, has anyone got any ideas what is going wrong here?

Upvotes: 15

Views: 26413

Answers (13)

Shakoor Hussain Attari
Shakoor Hussain Attari

Reputation: 1821

My issue was resolved by adding the below compiled files in the bin folder.

App_global.asax.compiled
App_global.asax.dll

Upvotes: 0

Radderz
Radderz

Reputation: 2868

If a required dll is missing from the bin directory (for example there could be a 3rd party dll which has been used in your latest build, but accidently excluded from deployment), then the Application_Start will not fire.

Upvotes: 0

Todd Harvey
Todd Harvey

Reputation: 347

also in IIS Manager turn on Dot Net debugging. It's under "Compilation"

Upvotes: 0

arame3333
arame3333

Reputation: 10193

My fix was an odd one. On my development machine I am using localhost and I changed the port number it used - and then it worked.

Upvotes: 0

Devraj Gadhavi
Devraj Gadhavi

Reputation: 3611

We tried a lot of things.

  1. global.asax works on local computer but not after i publish to server
  2. Global.asax is not publishing and event are not firing in Global.asax
  3. Global.asax not firing for Release build
  4. Mystery of Global.asax in ASP.NET MVC application

We also tried putting the below files in root and bin directories.

  1. App_global.asax.dll and App_global.asax.compiled files
  2. PrecompiledApp.config

None of it worked!

We had to put raw Global.asax instead of pre-compiled dll, in order to fire the global events, for our asp .net 2.0 website.

Hope this helps someone! Cheers! Happy coding! :D

Upvotes: 0

Etienne
Etienne

Reputation: 1106

I thought I had a similar problem, working on some old projects, I was under the impression that the global.asax was not running because the code would first go into building my authentication controller which would fail because of class not registered (that part happens in the global.asax).

Turned out it was due to a config item. When I moved the AuthenticationModule declaration into handler section in web config, it worked fine with IIS express.

Basically, because of a config item, another piece of code was being executed before global.asax, making me believe that it would not be called.

Upvotes: 0

jgreen
jgreen

Reputation: 1

1) iisreset /stop
2) push the published code to iis virtual directory's physical folder.
3) iisreset /start
4) make web request

Still not sure after this. the do a Thread.Sleep(60000); and attach with remote debugger to the process w3wp.exe imagename.
There may be more than one process of that name but this one is managed code also doesn't hurt to attach to multiple. Set the break point after the sleep. After the one minute sleep step through.

Upvotes: 0

liliancho
liliancho

Reputation: 121

I had a similar problem and I was wrestling with it for several days. The initial problem was something else - cookies not being set in Application's EndRequest handler. Finally I somehow managed to realize, that the problem actually was that the event is not being fired at all. It took some time to find that out, because all was working fine on my machine. But on the production server - quiet as a tomb.

I am only writing this, because I really hope to save from troubles at least one person.

The real reason for the problem was a missing global.asax file on the production server.

The global.asax file was present on my computer, because the development environment is located there. I had prepared a deployment bat file, which coppies files from the development folder, removes the unnecessary ones and makes a package. Well - the global.asax file was marked for deletion in that script. After starting to deploy it all the problems went away.

I hope I helped.

Upvotes: 12

RichardOD
RichardOD

Reputation: 29157

When you develop in Cassini you are running the application under the user's account- probably administrator. Once you've deployed to IIS, you are (hopefully) running under a lower privilidge account.

This lack of appropriate permissions is probably the reason why your application is not working correctly- I would check the security settings to write to the log (presumably you are writing to a log file?).

Upvotes: 0

Jacob
Jacob

Reputation: 78848

You may be getting a runtime exception that is occurring before your .NET code even gets a chance to run. If you look under the Event Viewer's Application logs, you may see some warnings or errors that will clue you in to what is happening.

Upvotes: 0

James Alexander
James Alexander

Reputation: 6302

In your deployed enviroment, what is the thing you're calling? The reason I ask is because if you're calling a WCF based web service (ending in .svc), then Applicaiton_Start will not fire as the call to WCF isn't going through the ASP.NET pipeline. This wouldn't necessarily rear it's head w/ Cassini.

Upvotes: 0

David
David

Reputation: 34563

If you make a request to your app does the "Application_Start" fire then? I don't believe it will be started until the first request is made.

Upvotes: 9

Andrew Hare
Andrew Hare

Reputation: 351516

How are you logging? Is it possible that your logging component is not correctly set up? For a quick test try throwing an exception inside Application_Start and that will tell you quickly whether or not the event is being raised.

Upvotes: 3

Related Questions