Fares Ayyad

Fares Ayyad

  • NA
  • 235
  • 74.6k

Web API controller: How to get the signed in user

Dec 11 2017 2:11 PM
Hello,
 
I'm trying to figure out how to get the current Identity user information, basically i do the following:
 
  1. [Produces("application/json")]  
  2.   [Route("api/GetPermissions")]  
  3.   public class GetPermissionsController : Controller  
  4.   {  
  5.   
  6.   private readonly ClaimsPrincipal _caller;  
  7.   //private readonly UserManager _userManager;  
  8.   //private readonly SignInManager _signInManager;  
  9.   //private readonly UserManager _manager;  
  10.   public GetPermissionsController(ClaimsPrincipal caller)  
  11.   {  
  12.     _caller = caller;  
  13.   }  
  14.   
  15.   [HttpGet]  
  16.   public IActionResult getPermissions()  
  17.   {  
  18.    var x= HttpContext.Request.LogonUserIdentity.Name;  
  19.     return new JsonResult(_caller.Claims.Select(  
  20.             c => new { c.Type, c.Value }));  
  21.   }  
when i tried to hit the api using POSTMAN, it returned with 500 interval server error. 
 
In my scenario i want to get the username to Angular service. 
 

Answers (1)