【问题标题】:Application restarted unexpectedly on Server 2012 and IIS 8.5应用程序在 Server 2012 和 IIS 8.5 上意外重启
【发布时间】:2017-05-11 20:10:24
【问题描述】:

在用户登录并执行一些并发操作后,$.ajax 会话意外过期或应用程序重新启动...

我已经检查了所有工具以了解主要原因,例如 Win 事件日志、IIS 日志和我的自定义日志信息,但没有适当的信息....

但经过一番谷歌搜索后,我转到this,上面说Inproc 模式不可靠且意外进程回收

或问题here 的答案说如果您使用InProc 会话状态并且AppPool 旋转下降,这将自动重置登录用户的所有会话。因此,请确保您正在使用其他会话状态方法,或者AppPool 的空闲超时时间长于.NET 会话超时时间。

谁能告诉我我哪里错了?

或者$.ajax限制发布数据或限制从webmethod返回的字符串len会导致这个问题吗?

我的web.config 和 IIS:

<sessionState timeout="120" mode="InProc"></sessionState>

更新:

根据我的测试,我可以看到应用程序重新启动,而不是 AppPoolw3wp

我在Application_Error 中遇到了异常,但仍然没有任何线索可以知道

   void Application_Error(object sender, EventArgs e)
    {
        _logging = new Logging(Global.LogPath);
        Exception exp = Server.GetLastError();
        _logging.Log(LoggingMode.Error, "An error accured through the application, EX{0}", exp.ToString());
    }

我也关注this link,照着说的做了,但没什么不同。

更新:

另一方面,我有一个通用处理程序来处理一些$.ajax 请求(并发请求)

  public override void ProcessRequest(HttpContext context)
    {
        base.ProcessRequest(context);

        HttpRequest request = context.Request;
        HttpResponse response = context.Response;
        response.ContentType = "text/plain";
        string action = request["Action"];
        switch (action)
        {
            case "LoadThumbnails":
                response.Write(LoadThumbnails(request.GetStudyUid()));
                break;
            case "LoadDetails":
                string detailsSeriesUid = request["seriesUID"];
                string detailsStartPoint = request["strStartPoint"];
                string detailsLengthPoint = request["strLenghtPoint"];
                response.Write(LoadDetails(request.GetStudyUid(), detailsSeriesUid, detailsStartPoint, detailsLengthPoint));
                break;
.
.
.

有时应用程序会在 LoadThumbnails()LoadDetails() 中重新启动。

他们可能会返回较大的 JSON 字符串,所以 response.Write() 重置应用程序有限制吗?

提前致谢。

【问题讨论】:

  • 检查日志文件可能是由于您的网站代码错误而不是 iis 错误导致应用程序意外结束
  • 感谢您的评论,是的,我检查过了,但我可以找到原因...
  • 你在项目中添加了 Elmah 吗?
  • 不,我没有,我有自定义日志系统,但我必须在任何我想登录的地方使用try-catch
  • 激活 elmah 并在此处添加日志

标签: c# asp.net session iis iis-8


【解决方案1】:

啊哈,经过多次头痛后,我已经妥善解决了问题......

正如微软所说,这个问题是由于磁盘 I/O 高而发生的,我同意 $.ajax 请求从服务获取流并将其写入 wbserver 硬盘,所以我将在此处发布解决方案可能会对某人有所帮助.

第 1 步:所以我改进了我的 Application_End 日志记录为:

 void Application_End(object sender, EventArgs e)
    {
        if (Logging == null)
            Logging = new Logging(ConfigurationManager.AppSettings["LogFile"]);
        int logLevel = Convert.ToInt32(ConfigurationManager.AppSettings["LogLevel"].ToString());
        Logging.Mode = (LoggingMode)logLevel;
        Logging.Log(LoggingMode.Error, "Application_End is running...");
        HttpRuntime runtime = (HttpRuntime)typeof(HttpRuntime).InvokeMember("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
        if (runtime == null)
        {
            Logging.Log(LoggingMode.Error, "Runtime is null...");
            return;
        }
        string shutDownMessage = (string)runtime.GetType().InvokeMember("_shutDownMessage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null);
        string shutDownStack = (string)runtime.GetType().InvokeMember("_shutDownStack", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null);
        Logging.Log(LoggingMode.Error, "Application restarted because of , Message:{0} , Stack:{1}", shutDownMessage, shutDownStack);
    }

第2步:意外重启后我的日志是:

2016-12-28 13:33:41.4791 [错误] [myApp.dll] Application_End 正在运行... 2016-12-28 13:33:41.4822 [错误] [myApp.dll] 由于消息:IIS 配置更改,应用程序重新启动 HostingEnvironment 启动关闭 HostingEnvironment 导致关机,堆栈:在 System.Environment.GetStackTrace(Exception e, Boolean needFileInfo) 在 System.Environment.get_StackTrace() 在 System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal() 在 System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand() 在 System.Web.Hosting.PipelineRuntime.StopProcessing() 在 System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler、RequestNotificationStatus&notificationStatus) 在 System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer,IntPtr nativeRequestContext,IntPtr moduleData,Int32 标志) 在 System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

第 3 步: 谷歌搜索 IIS 配置更改 终于找到了 妥妥的Microsoft KB about unexpected ASP.Net application shutdown

第 4 步:下载All supported x64-based versions of Windows Server 2012 R2 包并将其安装在上述服务器上。

第 5 步:冷静下来并感到高兴,因为问题已通过上述 4 个步骤解决!!!!

希望对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 2015-06-29
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    相关资源
    最近更新 更多