【问题标题】:The added or subtracted value results in an un-representable DateTime. Parameter name添加或减去的值会导致无法表示的 DateTime。参数名称
【发布时间】:2013-10-16 05:59:43
【问题描述】:

我不断收到这个异常,每隔一段时间就会发生一次。出于某种原因,我不认为它是我的代码,因为它也发生在不同的页面上。它也发生在我没有 DateTime 对象的页面上。

此外,当有应用程序异常进入一行代码时,出现的异常窗口是不同的。当发生此异常时,情况并非如此。在顶部它说代码堆栈只包含外部代码。

The added or subtracted value results in an un-representable DateTime.
 at System.DateTime.op_Addition(DateTime d, TimeSpan t)
 at System.Web.HttpContext.MustTimeout(DateTime utcNow)
 at System.Web.RequestTimeoutManager.RequestTimeoutEntry.TimeoutIfNeeded(DateTime now)
 at System.Web.RequestTimeoutManager.CancelTimedOutRequests(DateTime now)
 at System.Web.RequestTimeoutManager.TimerCompletionCallback(Object state)
 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
 at System.Threading.TimerQueueTimer.CallCallback()
 at System.Threading.TimerQueueTimer.Fire()
 at System.Threading.TimerQueue.FireNextTimers()

【问题讨论】:

  • 由于某种原因,我不认为它是我的代码,因为它也发生在不同的页面上看起来 IIS 正在做它通常做的事情并确保你的请求不是t 花费的时间比超时时间长。您是否将超时设置为 -1 或 999999999?
  • web.config 和其他地方。
  • 对我来说这就是问题所在,web.config 中的超时超出了范围。赞赏

标签: c# asp.net visual-studio-2012


【解决方案1】:

当我试图使 cookie 过期时,我得到了同样的结果,但现在 its 为我工作了 :)

HttpCookie cookie = new HttpCookie("appts");
cookie.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie);

【讨论】:

    【解决方案2】:
    Max Value 23:59:59.9999999, December 31, 9999,
    
    Min Value  00:00:00.0000000, January 1, 0001.
    
    If your DateTime + TimeSpan< MinValue  Or DateTime + TimeSpan>MaxValue
    

    你会得到异常,确保你保持在界限内。

    【讨论】:

      【解决方案3】:

      System.Web.HttpContext.MustTimeout 似乎是involved in coordinating request timeouts。为此,我想...

      System.DateTime.op_Addition(DateTime d, TimeSpan t)
      

      ...是MustTimeout 计算请求应该超时的时刻。它可以通过向请求的开始时间添加一些超时值来做到这一点。

      检查您没有任何人为高或无效的超时(web.config 或其他)。例如:

      <system.web>
          <httpRuntime executionTimeout="999999999999" />
      </system.web>
      

      记录了各种超时in this Stack Overflow answer

      【讨论】:

      • 我确实有 但我希望网站不会超时,因为用户上传文件需要一段时间,所以我不希望网站超时.另外,我是不是错过了什么。如果它太高,那么它不应该超时,对吧?那么有什么例外呢?
      • 您的executionTimeout 大约有 9512 年。 DateTime 最多可以代表一年 9999。将20139512 加在一起。 IIS 无法准确计算请求何时超时。尝试设置一个只有 7 千年的超时时间。
      • 还有一个问题。此超时是否与会话超时不同,我该如何设置另一个。看来这个超时是为了加载当前请求?我需要设置的另一个是会话到期的那个。
      • 有几个超时,用于连接、请求、会话(虽然仅适用于InProc 和其他支持超时的会话状态提供程序)、cookie 等。我建议你弄清楚你使用哪些(你可能会使用无 cookie 会话,在这种情况下 cookie 超时无关紧要),然后合理地配置它们。 But the client browser might enforce its own timeouts, so if your file uploads take too long consider breaking them up.
      猜你喜欢
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      相关资源
      最近更新 更多