問題Identity.GetUserId()如何找到用戶標識?
User.Identity.GetUserId()
如何找到當前用戶的ID?
它是否從Cookie中找到用戶標識,還是查詢數據庫?或者其他方法?
問題
出於某種原因,User.Identity.GetUserId()
回報null
當我添加一個有效Bearer Token
我的HTTP請求頭和請求發送到我的控制器的端點:
// MVC Controller Action Method
[Authorize]
public HttpResponseMessage(UserInfoViewModel model)
{
// Request passes the Authorization filter since a valid oauth token
// is attached to the request header.
string userId = User.Identity.GetUserId();
// However, userId is null!
// Other stuff...
}
你使用什麼驗證方法?它可以是匿名認證? – enkryptor