【发布时间】:2011-08-24 10:28:30
【问题描述】:
我研究了很多,但一无所获......
Application_Start 发布站点时未触发事件。但是它在本地主机中工作正常。发布后,我在 Bin 文件夹中获得了 App_global.asax.dll 和 App_GlobalResources.compiled,并且根目录下还有 PrecompiledApp.config。
【问题讨论】:
标签: c# .net asp.net global-asax
我研究了很多,但一无所获......
Application_Start 发布站点时未触发事件。但是它在本地主机中工作正常。发布后,我在 Bin 文件夹中获得了 App_global.asax.dll 和 App_GlobalResources.compiled,并且根目录下还有 PrecompiledApp.config。
【问题讨论】:
标签: c# .net asp.net global-asax
Application_Start 事件在应用程序第一次运行时触发。它与重新启动机器或重新启动 IIS 无关。您是否尝试过制作新的示例应用程序并测试该应用程序的 Application_Start 事件是否运行良好。如果是,那么您的应用程序配置已损坏。
也许重新启动您的应用程序池会对您有所帮助。
【讨论】:
可能是按预期触发了此事件,但由于您正在执行预编译的网络,并且处于发布模式,因此没有调试符号 - 在尝试远程调试应用程序的情况下 - 。
另一个可能的原因是它正在触发,但在 Application_Start 处理程序中引发了一些异常,并且由于每个应用程序生命周期都会调用一次,因此您需要回收应用程序的池或重新启动整个 IIS。
【讨论】:
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); }不清楚的请追问。
您的代码,在其他 cmets 中告诉:
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);
}
写入UserErrorLog\\UserErrorLog.txt 在正常的IIS 设置中会出现问题,它会尝试写入%SYSTEMROOT%\System32\Inetsrv 中的某个位置,这是IIS 的执行目录。您需要指定绝对路径 (C:\Logs\...) 或使用 HostingEnvironment.MapPath 来解析基于应用程序的路径 (HostingEnvironment.MapPath("~/App_Data/Logs/..."))
【讨论】: