application_start意外触发了asp.net

时间:2009-02-12 17:14:28

标签: asp.net global-asax web-applications

我正在查看一个asp.net应用程序,该应用程序调用应用程序中的数据库在global.asax中启动。这些调用大约需要3秒钟(取决于SQL缓存计划)才能运行。我注意到,当我第一次重新部署时,应用程序运行缓慢。我把它放在应用程序启动时对数据库的调用。但是几分钟后,应用程序再次需要时间来加载。

要了解发生了什么,我已写入日志文件(见下文)。从这个文件中你可以看到,当多个请求第一次出现在应用程序中时,应用程序启动多次。然后看起来application_start以随机方式触发(任何时间为2-10分钟)。

根据我对application_starts如何工作的理解,它应该只在应用程序FIRST启动时被触发,但它似乎是从多个客户端随机触发的!根据MSDN “应用程序启动时第一次触发Application_Start事件。”

任何人都可以帮我解决发生的事情吗?我正在使用IIS6和.net 2.0。它是我缺少的应用程序池设置。

非常感谢 Rippo

[12/02/2009 16:16:58] 91.84.25.241 - Application started, Sub MyRules started
[12/02/2009 16:17:06] 65.55.51.34 - Application started, Sub MyRules started
[12/02/2009 16:17:07] 91.84.25.241 - Application started, Sub MyRules completed
[12/02/2009 16:17:10] 65.55.51.34 - Application started, Sub MyRules completed
[12/02/2009 16:17:26] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:30] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:30] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:33] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:33] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:36] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:36] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:39] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:42] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:48] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:48] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:52] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:52] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:54] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:18:27] 91.84.25.241 - Application started, Sub MyRules started
[12/02/2009 16:18:31] 91.84.25.241 - Application started, Sub MyRules completed
[12/02/2009 16:18:31] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:18:33] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:29:26] 167.230.38.115 - Application started, Sub MyRules started
[12/02/2009 16:29:28] 167.230.38.115 - Application started, Sub MyRules completed
[12/02/2009 16:29:34] 82.110.42.84 - Application started, Sub MyRules started
[12/02/2009 16:29:37] 82.110.42.84 - Application started, Sub MyRules completed
[12/02/2009 16:29:38] 82.110.42.84 - Application started, Sub MyRules started
[12/02/2009 16:29:41] 82.110.42.84 - Application started, Sub MyRules completed
[12/02/2009 16:32:53] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:32:57] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:32:57] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:33:01] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:33:01] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:33:06] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:33:06] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:33:10] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:33:11] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:33:16] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:36:15] 65.55.51.34 - Application started, Sub MyRules started
[12/02/2009 16:36:17] 65.55.51.34 - Application started, Sub MyRules completed
[12/02/2009 16:41:37] 119.123.226.156 - Application started, Sub MyRules started
[12/02/2009 16:41:37] 62.49.121.122 - Application started, Sub MyRules started
[12/02/2009 16:41:40] 62.49.121.122 - Application started, Sub MyRules completed
[12/02/2009 16:41:40] 119.123.226.156 - Application started, Sub MyRules completed
[12/02/2009 16:41:41] 62.49.121.122 - Application started, Sub MyRules started
[12/02/2009 16:41:44] 62.49.121.122 - Application started, Sub MyRules completed
[12/02/2009 16:45:17] 84.70.249.242 - Application started, Sub MyRules started
[12/02/2009 16:45:19] 84.70.249.242 - Application started, Sub MyRules completed
[12/02/2009 16:47:03] 80.41.121.68 - Application started, Sub MyRules started
[12/02/2009 16:47:05] 80.41.121.68 - Application started, Sub MyRules completed
[12/02/2009 16:47:29] 81.179.26.249 - Application started, Sub MyRules started
[12/02/2009 16:47:31] 81.179.26.249 - Application started, Sub MyRules completed
[12/02/2009 16:47:59] 81.136.179.170 - Application started, Sub MyRules started
[12/02/2009 16:47:59] 81.136.179.170 - Application started, Sub MyRules started
[12/02/2009 16:48:02] 81.136.179.170 - Application started, Sub MyRules completed
[12/02/2009 16:48:02] 81.136.179.170 - Application started, Sub MyRules started
[12/02/2009 16:48:02] 81.136.179.170 - Application started, Sub MyRules completed
[12/02/2009 16:48:02] 81.136.179.170 - Application started, Sub MyRules started
[12/02/2009 16:48:04] 81.136.179.170 - Application started, Sub MyRules completed
[12/02/2009 16:48:04] 81.136.179.170 - Application started, Sub MyRules completed
[12/02/2009 16:52:35] 69.34.161.80 - Application started, Sub MyRules started
[12/02/2009 16:52:35] 69.34.161.80 - Application started, Sub MyRules started
[12/02/2009 16:52:35] 69.34.161.80 - Application started, Sub MyRules started
[12/02/2009 16:52:38] 69.34.161.80 - Application started, Sub MyRules completed
[12/02/2009 16:52:38] 69.34.161.80 - Application started, Sub MyRules started
[12/02/2009 16:52:39] 69.34.161.80 - Application started, Sub MyRules completed
[12/02/2009 16:52:39] 69.34.161.80 - Application started, Sub MyRules completed
[12/02/2009 16:52:40] 69.34.161.80 - Application started, Sub MyRules completed

5 个答案:

答案 0 :(得分:15)

检查应用重启的情况。 最近我们写了一些日志条目到bin文件夹,发生了完全相同的事情,我们不明白原因。 然后终于意识到对bin文件夹进行任何修改都会导致应用重启。

答案 1 :(得分:2)

检查事件日志,导致应用程序池回收。

答案 2 :(得分:2)

我遇到了多次调用Application_Start的问题,事实证明这是因为我设置了多个实例。愚蠢的错误,但我想注意它。

答案 3 :(得分:1)

我不知道为什么,但我在日志中看到了同样的事情。可能是因为它需要太长时间并且您同时有多个请求进入?无论如何,为了安全起见,我正在添加此代码:

public class MvcApplication : HttpApplication
{
    private static volatile bool hasRegisteredBgTasks = false;
    private static object registeredBgTasksLock = new object();

    protected void Application_Start()
    {
        lock (registeredBgTasksLock)
        {
            if (hasRegisteredBgTasks)
            {
                return;
            }
            // Actual start up code.
            hasRegisteredBgTasks = true;
        }
    }

    // Other Application methods...
}

答案 4 :(得分:0)

原来这是一个漏洞......