iis - windows azure 或 IIS 初始加载缓慢

标签 iis azure asp.net-mvc-4

我有一个托管在 Windows Azure 中的简单个人 MVC4 Web 应用程序。

这个网络应用程序的使用量非常少,初始调用非常慢,特别是当我早上尝试点击时。

我怀疑 IIS 正在休眠,需要唤醒。我找到这篇文章并提到这是 IIS 中的一个错误 http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8b3258e7-261c-49a0-888c-0b3e68b2af13这需要在 IIS 中进行设置,但我的 Web 应用程序托管在 Azure 中,有什么方法可以在 Web.config 文件中进行某种设置?

所有后续调用都很快。

这是我的个人页面。 javierdelacruz.com

谢谢。

最佳答案

两个选项:

  1. 启动任务
  2. OnStart 代码

有关启动任务,请参阅 this link .

对于 OnStart 代码,尝试这样的函数(该函数还执行更多操作):

    private const string _web_app_project_name = "Web";

    public static void SetupDefaultEgConfiguration(int idleTimeoutInMinutes = 1440, int recycleTimeoutInMinutes = 1440, string appPoolName = "My Azure App Pool", bool enableCompression = true)
    {
        if (!RoleEnvironment.IsEmulated)
        {
            Trace.TraceWarning("Changing IIS settings upon role's OnStart. Inputs: ({0}, {1}, {2}, {3}", idleTimeoutInMinutes, recycleTimeoutInMinutes, appPoolName, enableCompression);

            // Tweak IIS Settings
            using (var iisManager = new ServerManager())
            {
                try
                {
                    var roleSite = iisManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_" + _web_app_project_name];
                    if (enableCompression)
                    {
                        //================ Enable or disable static/Dynamic compression ===================//
                        var config = roleSite.GetWebConfiguration();
                        var urlCompressionSection = config.GetSection("system.webServer/urlCompression");
                        urlCompressionSection["doStaticCompression"] = true;
                        urlCompressionSection["doDynamicCompression"] = true;
                        Trace.TraceWarning("Changing IIS settings to enable static and dynamic compression");
                    }

                    //================ To change ApplicationPool name ================================//
                    var app = roleSite.Applications.First();
                    app.ApplicationPoolName = appPoolName;

                    //================ To change ApplicationPool Recycle Timeout ================================//
                    var appPool = iisManager.ApplicationPools[app.ApplicationPoolName];
                    appPool.Recycling.PeriodicRestart.Time = new TimeSpan(0, recycleTimeoutInMinutes, 0);

                    //================ idletimeout ====================================================//               
                    var defaultIdleTimeout = iisManager.ApplicationPoolDefaults.ProcessModel.IdleTimeout;
                    var newIdleTimeout = new TimeSpan(0, idleTimeoutInMinutes, 0);
                    if ((int)newIdleTimeout.TotalMinutes != (int)defaultIdleTimeout.TotalMinutes)
                    {
                        appPool.ProcessModel.IdleTimeout = newIdleTimeout;
                    }

                    // Commit the changes done to server manager.
                    iisManager.CommitChanges();
                }
                catch (Exception e)
                {
                    Trace.TraceError("Failure when configuring IIS in Azure: " + e.ToString().Take(63000));
                }
            }
        }
    }

Source and some more details对于我在此处包含的功能 - 您可能需要一些依赖项才能完成此操作。

关于iis - windows azure 或 IIS 初始加载缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14387986/

相关文章:

VS2015 中的 Azure 调试环境启动时崩溃

azure - 如何限制应用程序端点在浏览器中加载?

asp.net - Visual Studio 2012 无法编译动态表达式和模型类型

asp.net - IIS 服务器内存不足会导致 SQL 超时(SQL Server 在单独的机器上)吗?

node.js - Windows Azure 云服务 IIS 有时返回 503 错误

asp.net - 无法启动网站 IIS HRESULT : 0x80070020)

javascript - 从 Kendo UI dateTimepicker 隐藏/禁用周末

asp.net - 超过 IIS 7.5 和 .NET 中的 2GB 文件上传限制

c# - 是否可以通过代码将证书上传到门户?

asp.net-mvc-4 - ASP.NET MVC 4 OAuthWebSecurity 不起作用