title: MVC 5 Access Claims Identity User Data
body: <p>I am developing an <strong>MVC 5</strong> web application using <strong>Entity Framework 5 Database First</strong> approach. I am using <strong>OWIN</strong> for the authentication of Users. Below shows my Login method within my Account Controller.</p>
  
  <pre><code>public ActionResult Login(LoginViewModel model, string returnUrl)
  {
      if (ModelState.IsValid)
      {
          var user = _AccountService.VerifyPassword(model.UserName, model.Password, false);
          if (user != null)
          {
              var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, model.UserName), }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role);
  
              identity.AddClaim(new Claim(ClaimTypes.Role, "guest"));
              identity.AddClaim(new Claim(ClaimTypes.GivenName, "A Person"));
              identity.AddClaim(new Claim(ClaimTypes.Sid, user.userID)); //OK to store userID here?
  
              AuthenticationManager.SignIn(new AuthenticationProperties
              {
                  IsPersistent = model.RememberMe
              }, identity);
  
              return RedirectToAction("Index", "MyDashboard");
          }
          else
          {
              ModelState.AddModelError("", "Invalid username or password.");
          }
      }
      // If we got this far, something failed, redisplay form
      return View(model);
  }
  </code></pre>
  
  <p>As you can see I'm creating a <strong>ClaimsIdentity</strong> and adding several claims to it, then passing it to <strong>OWIN</strong> using the <strong>AuthenticationManager</strong> to perform the sign in.</p>
  
  <p><strong>The problem I am having is that I'm not sure how to access the claims in the rest of my application, either in Controllers or in Razor Views.</strong></p>
  
  <p>I had tried the approach listed in this tutorial</p>
  
  <p><a href="http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/" rel="noreferrer">http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/</a></p>
  
  <p>For example, I tried this in my Controller code in an attempt to get access to the values passed into the Claims, however, the user.Claims is equal to null</p>
  
  <pre><code>var ctx = HttpContext.GetOwinContext();
  ClaimsPrincipal user = ctx.Authentication.User;
  IEnumerable&lt;Claim&gt; claims = user.Claims;
  </code></pre>
  
  <p>Perhaps I am missing something here. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Based on Darin's answer, I added his code but still I fail to see access to the Claims. Please see screenshot below showing what I see when hovered over identity.Claims.</p>
  
  <p><img src="https://i.stack.imgur.com/Uk6RQ.jpg" alt="enter image description here"></p>