【问题标题】:web api get user info inside controllerweb api获取控制器内的用户信息
【发布时间】:2016-10-24 22:44:05
【问题描述】:

我正在使用标准的 owin asp.net.identity 机制来授权用户使用他们的访问令牌。在我的控制器内部,我想知道是谁发送了请求。我怎么能做到?我能否以某种方式从控制器内部的请求中检索访问令牌?

我试过了:

public HttpResponseMessage Get([FromUri] GetParameters parameters)
{
   Var identity = RequestContext.Principal.Identity;
}

它并没有给我很多,因为大多数属性总是空的。

【问题讨论】:

    标签: c# asp.net-web-api asp.net-identity


    【解决方案1】:

    试试

    string token = HttpContext.Current.Request.LogonUserIdentity.Token.ToString();
    

    【讨论】:

    • 返回“Microsoft.Win32.SafeHandles.SafeAccessTokenHandle”
    猜你喜欢
    • 2020-10-16
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2015-02-25
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    相关资源
    最近更新 更多