【问题标题】:Application_Start event not firing when published发布时未触发 Application_Start 事件
【发布时间】:2011-08-24 10:28:30
【问题描述】:

我研究了很多,但一无所获......

Application_Start 发布站点时未触发事件。但是它在本地主机中工作正常。发布后,我在 Bin 文件夹中获得了 App_global.asax.dll 和 App_GlobalResources.compiled,并且根目录下还有 PrecompiledApp.config。

【问题讨论】:

    标签: c# .net asp.net global-asax


    【解决方案1】:

    Application_Start 事件在应用程序第一次运行时触发。它与重新启动机器或重新启动 IIS 无关。您是否尝试过制作新的示例应用程序并测试该应用程序的 Application_Start 事件是否运行良好。如果是,那么您的应用程序配置已损坏。

    也许重新启动您的应用程序池会对您有所帮助。

    【讨论】:

    • 感谢马苏德的回复。是的,它在 localhost 中工作正常,但是一旦网站发布,事件就不会触发。任何线索..
    • 你的 windows 版本是多少?
    • Windows Server 2003 企业版
    • 考虑我的场景:** protected void Application_Start(Object sender, EventArgs e) { logfile.ErrorLog("UserErrorLog\\UserErrorLog.txt", "Application_Start method executed at " + System.DateTime.Now );做一些工作(); logfile.ErrorLog("UserErrorLog\\UserErrorLog.txt", "Application_Start 方法执行结束于" + System.DateTime.Now); }**
    • 这个问题很可能是你的应用服务器而不是你的应用。
    【解决方案2】:

    可能是按预期触发了此事件,但由于您正在执行预编译的网络,并且处于发布模式,因此没有调试符号 - 在尝试远程调试应用程序的情况下 - 。

    另一个可能的原因是它正在触发,但在 Application_Start 处理程序中引发了一些异常,并且由于每个应用程序生命周期都会调用一次,因此您需要回收应用程序的池或重新启动整个 IIS。

    【讨论】:

    • 没有这样的例外。一旦控件进入 Application_Start 事件,我就会登录文本文件。问题是控制本身没有参加这个活动。考虑我的场景:protected void Application_Start(Object sender, EventArgs e) { logfile.ErrorLog("UserErrorLog\\UserErrorLog.txt", "Application_Start method executed at " + System.DateTime.Now);做一些工作(); logfile.ErrorLog("UserErrorLog\\UserErrorLog.txt", "Application_Start 方法执行结束于" + System.DateTime.Now); }
    • 这个有限的信息我帮不了你,我试着给你一些基本的提示。
    • 这是我正在尝试做的示例代码。在本地机器上完美运行,但在调试模式下发布时,事件 Application_Start 没有触发。我检查了是否有任何异常,但不幸的是没有异常。 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 中发布编码不是分析问题的好地方。如果不执行实际代码,将很难确定。
    【解决方案3】:

    您的代码,在其他 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/..."))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 2011-10-09
      • 2013-12-22
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      相关资源
      最近更新 更多