【问题标题】:How to know the current user identity [duplicate]如何知道当前用户身份[重复]
【发布时间】:2012-08-14 09:27:09
【问题描述】:

在一个使用表单身份验证的mvc .net web应用程序中,如何知道控制器中当前的用户身份?

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3


    【解决方案1】:

    你可以使用User.Identity.Name:

    [Authorize]
    public ActionResult SomeAction()
    {
        string currentlyLoggedInUsername = User.Identity.Name;
        ...
    }
    

    【讨论】:

      【解决方案2】:
        this.HttpContext.User.Identity
      

      请注意,您还应该检查是否

        this.HttpContext.User.Identity.IsAuthenticated
      

      区分匿名用户和经过身份验证的用户。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多