gpt4 book ai didi

asp.net-mvc - Mvc 3 应用程序随机停止(特别是在回收后)IIS 7.5 集成模式

转载 作者:行者123 更新时间:2023-12-05 01:25:01 39 4
gpt4 key购买 nike

我们有一个在 IIS 7 下运行的 MVC 3 应用程序,应用程序池托管管道模式是集成

此应用程序突然变得不稳定,这意味着会出现如下错误。

Log Name:      Application
Source: ASP.NET 4.0.30319.0
Date: 04.02.2014 12:01:16
Event ID: 1309
Task Category: Web Event
Level: Warning
Keywords: Classic
User: N/A
Computer:
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 04.02.2014 12:01:16
Event time (UTC): 04.02.2014 10:01:16
Event ID: 9896973154a54e5b88e6f1799922e853
Event sequence: 6
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/3/ROOT-1-130359816693915362
Trust level: Full
Application Virtual Path: /
Application Path: D:\WebSites\
Machine name: DC1VMCIFWEB02

Process information:
Process ID: 4152
Process name: w3wp.exe
Account name: NT AUTHORITY\SYSTEM

Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
at System.Web.PipelineModuleStepContainer.GetEventCount(RequestNotification notification, Boolean isPostEvent)
at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)

这也是我们的 global.asax.cs 代码,我想知道这段代码有什么问题;

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

}

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();

RegisterRoutes(RouteTable.Routes);
log4net.Config.XmlConfigurator.Configure();
}

protected void Application_AcquireRequestState(object sender, EventArgs e)
{
Response.Cache.SetExpires(DateTime.Now.AddSeconds(0));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetValidUntilExpires(true);


if (HttpContext.Current.Session != null)
{
CultureInfo ci = (CultureInfo)this.Session["Culture"];
if (ci == null)
{
string langName = "tr";

if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length != 0)
{
langName = HttpContext.Current.Request.UserLanguages[0].Substring(0, 2);
}
ci = new CultureInfo(langName);
this.Session["Culture"] = ci;
}
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
}

protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();

Application[HttpContext.Current.Request.UserHostAddress.ToString()] = ex;

Class.LogClass.Error(this.GetType().ToString(), "Application_Error : ", ex);
}

最佳答案

关于这一行:

Application[HttpContext.Current.Request.UserHostAddress.ToString()] = ex;

根据 MSDN :

Application state is stored in memory on the server, so a large amount of data in application state can fill up server memory quickly. If the application is restarted, application state data is lost. Application state is not shared between multiple servers within a Web farm or between worker processes in a Web garden. Finally, application state is free-threaded, so any data that is stored in application state must have built-in synchronization support. For more information about these considerations, see ASP.NET Application State Overview and ASP.NET State Management Recommendations.

基本上,您存储的是全局变量列表,它们是 UserHostAddress/Exception object 映射。本质上,这是自上次应用程序池回收以来访问该站点的每个 IP 地址的最后一个错误。由于此状态仅在应用程序池回收时才被清除,因此它就像一个缓慢的内存泄漏。您的应用程序池超时时间越长,用户越有可能在某处遇到异常,您运行服务器时越有可能内存不足。

不清楚为什么要将异常放入持久位置,但如果您的意图是允许当前请求能够显示异常,更好的选择是将其存储在 HttpContext.Items,它只会持续当前请求的生命周期。这将确保应用程序错误最终不会导致服务器内存不足。

我不确定这是导致您的应用程序不稳定的原因,但这是一个很好的起点。

关于asp.net-mvc - Mvc 3 应用程序随机停止(特别是在回收后)IIS 7.5 集成模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21574419/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com