Get the current user, within an ApiController action, without passing the userID as a parameter

前端 未结 8 1376
时光说笑
时光说笑 2020-12-02 09:50

How do we get the current user, within an secure ApiController action, without passing the userName or userId as a parameter?

We assume that this is available, beca

相关标签:
8条回答
  • 2020-12-02 10:24

    Karan Bhandari's answer is good, but the AccountController added in a project is very likely a Mvc.Controller. To convert his answer for use in an ApiController change HttpContext.Current.GetOwinContext() to Request.GetOwinContext() and make sure you have added the following 2 using statements:

    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.Owin;
    
    0 讨论(0)
  • 2020-12-02 10:24

    In .Net Core use User.Identity.Name to get the Name claim of the user.

    0 讨论(0)
提交回复
热议问题