In MVC 5 project i m using Microsoft.AspNet.Identity. I want authorize to user with cookie and session. I record sessions on redis.
<sessionState mode="Custom" customProvider="MySessionStateStore"> <providers> <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="192.168.13.197" port = "6379" accessKey = "" ssl = "false" throwOnError = "true" retryTimeoutInMilliseconds = "5000" databaseId = "0" applicationName = "IddaaWebSite" connectionTimeoutInMilliseconds = "5000" operationTimeoutInMilliseconds = "1000"/> </providers> </sessionState> New Session object must create when user login.
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await UserManager.FindAsync(model.UserName, model.Password); if (user != null) { if (user.EmailConfirmed == false) return View("_ActivationCodeManuel", user); await SignInAsync(user, model.RememberMe); var uSo = JsonConvert.SerializeObject(user); Session.Add(user.Id, uSo); return RedirectToLocal(returnUrl); } ModelState.AddModelError("", "E-posta adresinizi ya da şifrenizi hatalı girdiniz."); } // If we got this far, something failed, redisplay form return View(model); } And if session expried on redis, it should link to login page or if user start a new session on another computer the current should expried. But now it is working with only cookie.
[Authorize] public ActionResult Index() { var id = User.Identity.GetUserId(); return View(); } I think i need to ovveride Authorize method. it should check cookie and session on redis ?