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

前端 未结 8 1379
时光说笑
时光说笑 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:06

    You can also access the principal using the User property on ApiController.

    So the following two statements are basically the same:

    string id;
    id = User.Identity.GetUserId();
    id = RequestContext.Principal.Identity.GetUserId();
    

提交回复
热议问题