开发者

Application_Start event not firing when published

开发者 https://www.devze.com 2023-03-30 02:43 出处:网络
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_GlobalR

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_GlobalR开发者_开发问答esources.compiled in Bin folder and also have PrecompiledApp.config at root.


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.


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.


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/..."))

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号