title: How to do session management in aspnet identity?
body: <p>I am using <strong>Asp.net identity</strong> for <strong>Login,Register,Forgot Password</strong> etc and source code is taken from this below link:</p>
  
  <p><a href="http://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-web-app-with-email-confirmation-and-password-reset">http://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-web-app-with-email-confirmation-and-password-reset</a></p>
  
  <p><a href="http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity">http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity</a>.</p>
  
  <p>Now i have 1 table that is UserMaster and during registration i am asking for this following fields:
  <strong>FullName,EmailId,Password,ContactNumber,Gender</strong>.</p>
  
  <p>My UserMaster Contains this following fields:<strong>Id,FullName,EmailId,ContactNumber,Gender</strong></p>
  
  <p>Now when user will submit registration form this FullName,EmailId,ContactNumber,Gender will be saved in <strong>UserMaster</strong> along with the <strong>Email,Password will be saved in AspnetUser</strong>.</p>
  
  <p><strong>My Register Method</strong> is same as provided in above 2 links.</p>
  
  <p>Here you might notice that there is <strong>no relationship between my UserMaster and AspnetUser</strong> so during login when user will enter his email id to login i will use this method <code>await SignInManager.PasswordSignInAsync</code> to verify user and if this method returns success then what i will do is use this email id and check this email in my UserMaster and where match will be found i will fetch that UserId from UserMaster and store it in session and use thorugh out my application in my login method like below:</p>
  
  <pre><code> public async Task&lt;ActionResult&gt; Login(LoginViewModel model, string returnUrl)
              {
                  if (!ModelState.IsValid)
                  {
                      return View(model);
                  }
  
                  // This doesn't count login failures towards account lockout
                  // To enable password failures to trigger account lockout, change to shouldLockout: true
                  var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
                  switch (result)
                  {
                      case SignInStatus.Success:
                    using (var context = new MyEntities())
                          {
                              var fetchUSerId = context.UserMaster.Where(t =&gt; t.Email == model.Email).Select(t=&gt;t.UserId).SingleOrDefault();
                              Session["UserId"] = fetchUSerId;
                          }
                          return RedirectToLocal(returnUrl);
                      case SignInStatus.LockedOut:
                          return View("Lockout");
                      case SignInStatus.RequiresVerification:
                          return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                      case SignInStatus.Failure:
                      default:
                          ModelState.AddModelError("", "Invalid login attempt.");
                          return View(model);
                  }
              }
  </code></pre>
  
  <p>I am talking about this in my login method:</p>
  
  <pre><code> case SignInStatus.Success:
                        using (var context = new MyEntities())
                              {
                                  var fetchUSerId = context.UserMaster.Where(t =&gt; t.Email == model.Email).Select(t=&gt;t.UserId).SingleOrDefault();
                                  Session["UserId"] = fetchUSerId;
                              }
  </code></pre>
  
  <p>Is this an appropriate way or still a better way and i want to store entire user object instead of just storing User Id.</p>
  
  <p>So can anybody tell me how to do this with aspnet identity??</p>