代码之家  ›  专栏  ›  技术社区  ›  Ropstah

.NET MVC-在global.asax中检查isinRole()的位置?

  •  1
  • Ropstah  · 技术社区  · 16 年前

    在global.asax生命周期的哪个部分,我可以安全地“使用” User 对象?我使用默认值 forms authentication 注意到:

    Sub Application_BeginRequest()
        'Context.User Is Nothing
    End Sub
    
    Sub Application_AuthenticateRequest()
        'Context.User Is Nothing
    End Sub
    
    Sub Application_AuthorizeRequest()
        'Context.User is available
        'Context.User.IsInRole() returns false while user is in role
    End Sub
    

    好像 AuthorizeRequest() 不过,应该是那个地方 IsInRole() 不返回预期的 true . 我是不是错过了什么?

    1 回复  |  直到 16 年前
        1
  •  3
  •   ckramer    16 年前

    我认为您实际上想在Post-AuthenticateRequest中执行此操作:

    void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
    {
        // Context.User is available now, and IsInRole() should work fine;
    }