I have an MVC controller that aims to read the user's info from HTTP header. The header contains user info that returns from a single sign on (SiteMinder). SiteMinder redirects the user to the company login page and returns back to my app along with cookie and HTTP header. The HTTP header contains user's info. My controller is supposed to get those info and display it in the navigation bar.
Here is the controller code:
[HttpGet]
public async Task<IActionResult> GetUser()
{
var person = Request.Headers["HTTP_JHED_UID"].ToString();
if (repository.GetJhedUser(person) != null)
{
var user = await repository.GetUser(person);
var userDto = mapper.Map<User, UserForDisplayDto>(user);
return Ok(userDto);
}
else
{
return null;
}
}
And here is my corresponded repository:
public string GetJhedUser(string value)
{
return context.Users.Where(x => x.JHED_ID == value).ToString();
}
public async Task<User> GetUser(string id, bool includeRelated = true)
{
if(!includeRelated)
return await context.Users.FindAsync(id);
return await context.Users
.SingleOrDefaultAsync(s => s.JHED_ID == id);
}
I receive 500 server error. I am sure that the header has those values.
EDIT: Here is an image of debugging. Even I tried with "Date" the value is nothing. Please note that I refactored my codes to @Nkosi's code below
How to get those user's info (in this case just username) from header so that I can display in my HTML template?

if (Request.Headers["HTTP_JHED_UID"].Any()), but the main problem is - what exact exception do you get? Syntax error in JSON response means that you got an error html page in response, so what's in there?BadRequest. I don't think the issue is on the client side. Somehow the controller doesn't get the header value.