Ashish Kumar
Ashish Kumar

Reputation: 21

Application_Start event not firing when published

I researched a lot but got nothing...

Application_Start event is not firing when published the site. However it works fine in localhost. After publishing i got the App_global.asax.dll and App_GlobalResources.compiled in Bin folder and also have PrecompiledApp.config at root.

Upvotes: 2

Views: 1006

Answers (3)

sisve
sisve

Reputation: 19791

Your code, told in other comments:

protected void Application_Start(Object sender, EventArgs e) {
    logfile.ErrorLog("UserErrorLog\\UserErrorLog.txt", "Application_Start method executed at " + System.DateTime.Now);
    DoSomeWork();
    logfile.ErrorLog("UserErrorLog\\UserErrorLog.txt", "Application_Start method execution ends at " + System.DateTime.Now);
}

Writing to UserErrorLog\\UserErrorLog.txt will be problematic in a normal IIS setup, it will attempt to write somewhere within %SYSTEMROOT%\System32\Inetsrv which is the executing directory of IIS. You need to either specify an absolute path (C:\Logs\...) or using HostingEnvironment.MapPath to resolve an application based path (HostingEnvironment.MapPath("~/App_Data/Logs/..."))

Upvotes: 0

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64943

Possibly it's this event is fired as expected, but since you're executing a precompiled web, and in release mode, there're no debugging symbols - in the case of trying to remotely debug your application -.

Another possible reason is it's firing, but some exception is thrown within Application_Start handler, and since this is called once per application life-cycle, you'll need to recycle application's pool or restart the entire IIS.

Upvotes: 0

masoud ramezani
masoud ramezani

Reputation: 22950

Application_Start event is fired when the Application is ran for the first time. It has nothing to do with restarting machine or restarting IIS. Did you tried in making a new sample app and test that Application_Start event of that application ran well or not. If yes then you application configuration is corrupted someway.

maybe restarting your application pool can help you.

Upvotes: 4

Related Questions