首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何判断IIS应用程序池被回收的原因

如何判断IIS应用程序池被回收的原因
EN

Stack Overflow用户
提问于 2011-03-26 23:39:48
回答 1查看 14.3K关注 0票数 18

背景:

我已经将一个在我的机器上运行的ASP.NET MVC3应用程序部署到一个shared hosting provider上,并且发现了一些似乎与被回收的应用程序池有关的问题。主机已将回收配置为在以下任何一种情况下发生:

  • 内存使用率超过200 75
  • CPU使用率超过75% (假设持续一段时间)
  • 20分钟的空闲时间

在我的开发机器上的限制更宽松,所以我在开发过程中没有看到像这样的回收。我没有管理权限访问共享主机(可以理解),所以我无法读取事件日志来了解为什么会发生这种回收。

问题:

有没有一种方法可以让我找出为什么我的应用被回收(例如在Application_End中),这样我就可以记录它来帮助我的调试?

EN

回答 1

Stack Overflow用户

发布于 2016-03-23 02:31:29

下面是从https://mitchelsellers.com/blog/article/logging-asp-net-application-restarts找到的好代码

代码语言:javascript
复制
//  obtain the shutdown reason
System.Web.ApplicationShutdownReason shutdownReason = System.Web.Hosting.HostingEnvironment.ShutdownReason;
string shutdownDetail = "";

//Evaluate which option caused the error
switch (shutdownReason)
{
    case ApplicationShutdownReason.BinDirChangeOrDirectoryRename:
        shutdownDetail = "A change was made to the bin directory or the directory was renamed";
        break;
    case ApplicationShutdownReason.BrowsersDirChangeOrDirectoryRename:
        shutdownDetail = "A change was made to the App_browsers folder or the files contained in it";
        break;
    case ApplicationShutdownReason.ChangeInGlobalAsax:
        shutdownDetail = "A change was made in the global.asax file";
        break;
    case ApplicationShutdownReason.ChangeInSecurityPolicyFile:
        shutdownDetail = "A change was made in the code access security policy file";
        break;
    case ApplicationShutdownReason.CodeDirChangeOrDirectoryRename:
        shutdownDetail = "A change was made in the App_Code folder or the files contained in it";
        break;
    case ApplicationShutdownReason.ConfigurationChange:
        shutdownDetail = "A change was made to the application level configuration";
        break;
    case ApplicationShutdownReason.HostingEnvironment:
        shutdownDetail = "The hosting environment shut down the application";
        break;
    case ApplicationShutdownReason.HttpRuntimeClose:
        shutdownDetail = "A call to Close() was requested";
        break;
    case ApplicationShutdownReason.IdleTimeout:
        shutdownDetail = "The idle time limit was reached";
        break;
    case ApplicationShutdownReason.InitializationError:
        shutdownDetail = "An error in the initialization of the AppDomain";
        break;
    case ApplicationShutdownReason.MaxRecompilationsReached:
        shutdownDetail = "The maximum number of dynamic recompiles of a resource limit was reached";
        break;
    case ApplicationShutdownReason.PhysicalApplicationPathChanged:
        shutdownDetail = "A change was made to the physical path to the application";
        break;
    case ApplicationShutdownReason.ResourcesDirChangeOrDirectoryRename:
        shutdownDetail = "A change was made to the App_GlobalResources foldr or the files contained within it";
        break;
    case ApplicationShutdownReason.UnloadAppDomainCalled:
        shutdownDetail = "A call to UnloadAppDomain() was completed";
        break;
    default:
        shutdownDetail = "Unknown shutdown reason";
        break;
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5443356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档