Can I access IIdentity from Web API

后端 未结 4 1951
有刺的猬
有刺的猬 2020-12-25 09:45

I\'m adding some Web API services to an existing MVC application. I have a model binder for my MVC controllers to get the user object stored in a CustomIdentity. I\'m tryi

4条回答
  •  春和景丽
    2020-12-25 10:29

    You can try to use this extension method from System.ServiceModel.dll:

    public static IPrincipal GetUserPrincipal(this HttpRequestMessage request);
    

    as:

    IPrincipal principal = request.GetUserPrincipal();
    IIdentity identity = principal.Identity;
    

提交回复
热议问题