【问题标题】:ASP .NET: Thread.CurrentPrincipal is lost when customErrors contains redirectMode="ResponseRewrite"ASP .NET:当 customErrors 包含 redirectMode="ResponseRewrite" 时,Thread.CurrentPrincipal 丢失
【发布时间】:2010-09-22 18:53:58
【问题描述】:

我在处理 Authentication_Request 的模块之一中设置了我的自定义主体。然后我将它设置为 HttpContext.User。这设置了我的 HttpContext.User 和 Thread.CurrentPrincipal。现在,当发生错误并且 customErrors 部分包含“ResponseRewrite”时,Thread.CurrentPrincipal 在我的 ASPX 错误页面上被重置为通用主体。但我的 HttpContext.User 仍然包含我的自定义主体。如果 customErrors 部分包含“ResponseRedirect”,则不会发生这种情况。这是预期的行为吗?

【问题讨论】:

  • 这个标签是否正确,听起来不像是一个 ASP 问题。 ASP.NET?

标签: asp.net custom-errors


【解决方案1】:

我怀疑服务器正在启动一个单独的线程来执行错误页面。您可以通过将以下内容放入 Global.asax 来重置它 (Thread.CurrentPrincipal)。

  protected void Application_AuthenticateRequest(object sender, EventArgs e) {
        Thread.CurrentPrincipal = HttpContext.Current.User;
  }

此行将确保在对您的应用程序的每个请求上两者都是同步的。

【讨论】:

    猜你喜欢
    • 2010-10-21
    • 1970-01-01
    • 2010-12-08
    • 2013-06-07
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    相关资源
    最近更新 更多