title: How to implement auto user login using asp.net mvc
body: <p>We are using mvc framework 6, identity framework 3 and EF 7 with sql server. The webapp requires user authentication and authorization. But there's a situation when we want to authenticate/authorize user from query string. I am having problem in creating usermanager/signinmanager.
  This is what AccountController looks like for login</p>
  
  <pre><code>[Authorize]
  public class AccountController : Controller
  {
      private readonly ApplicationDbContext _dbContext;
      public AccountController(ApplicationDbContext dbContext, UserManager&lt;ApplicationUser&gt; userManager, SignInManager&lt;ApplicationUser&gt; signInManager)
      {
          _dbContext = dbContext;
          UserManager = userManager;
          SignInManager = signInManager;
      }
  
      public UserManager&lt;ApplicationUser&gt; UserManager { get; private set; }
  
      public SignInManager&lt;ApplicationUser&gt; SignInManager { get; private set; }
  
      //
      // GET: /Account/Login
      [HttpGet]
      [AllowAnonymous]
      public IActionResult Login(string returnUrl = null)
      {
          ViewBag.ReturnUrl = returnUrl;
          return View();
      }
  
      //
      // POST: /Account/Login
      [HttpPost]
      [AllowAnonymous]
      [ValidateAntiForgeryToken]
      public async Task&lt;IActionResult&gt; Login(LoginViewModel model, string returnUrl = null)
      {
          ViewBag.ReturnUrl = returnUrl;
          if (ModelState.IsValid)
          {
              // This doesn't count login failures towards account lockout
              // To enable password failures to trigger account lockout, set shouldLockout: true
              var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
              if (result.Succeeded)
              {
                  return RedirectToLocal(returnUrl);
              }
              if (result.RequiresTwoFactor)
              {
                  return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
              }
              if (result.IsLockedOut)
              {
                  return View("Lockout");
              }
              else
              {
                  ModelState.AddModelError(string.Empty, "Invalid username or password.");
                  return View(model);
              }
          }
  
          // If we got this far, something failed, redisplay form
          return View(model);
      }
  </code></pre>
  
  <p>For auto login from URL string, I want to create or instantiate SigninManager object to I so I could use PasswordSignInAysync method. But I am not sure how to do that. This is what I have , but I am not sure about the arguments to pass.</p>
  
  <pre><code>    [HttpGet]
      public async Task&lt;IActionResult&gt; Index()
      {
         //from url
         if(Request != null)
          {
              if(Request.Query["emailId"] != null)
              {
  
                  var store = new UserStore&lt;ApplicationUser&gt;(_dbContext);
                  var manager = new UserManager&lt;ApplicationUser&gt;(store,null,null,null,null,null,null,null,null,null);
                  //var userstore = new IUserStore(ApplicationUser);
                  //var user = new UserManager();
                  var user = new ApplicationUser { UserName = "someone@XXX.com" };
  
                  var signinmanager = new SignInManager&lt;ApplicationUser&gt;(manager,);
  
                  var result =  await SignInManager.PasswordSignInAsync(Request.Query["emailId"],
                                          Request.Query["TokenId"], false, shouldLockout: false);
                  if (result.Succeeded)
                  {
                      return RedirectToAction("MyHome", "People");
                  }
                  return RedirectToAction("MyHome",  "People");
              }
          }
  
  
      }
  </code></pre>