title: Extract values from HttpContext.User.Claims
body: <p>I'm trying to extract an email address from <code>HttpContext.User.Claims</code> and I'd like to ask for help to come up with a better way to code this (maybe using LINQ?)</p>
  
  <p>The way I'm doing it now seems very hacky.</p>
  
  <pre><code>var userClaimsList = HttpContext.User.Claims.ToList();
  
  // List is of varying length but email is always 3rd from the bottom.
  int emailPosition = userClaimsList.Count()-3; 
  string searchString = "preferred_username: "; 
  
  // dirtyEmail = "preferred_username: xyz@emailcom"
  string dirtyEmail = userClaimsList[emailPosition].ToString();
  string cleanEmail = dirtyEmail.Replace(searchString, "").ToLower().Trim();
  </code></pre>
  
  <p>I've tried the LINQ solutions recommended <a href="https://stackoverflow.com/questions/1175645/find-an-item-in-list-by-linq?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">in another post</a> but receive the error <code>Operator == cannot be applied to operands of type 'Claim' and 'string'</code>.</p>