After authenticating user using Identity 2, I'd like to keep some information about him or her in Session. I can access Session in the immediate action method, which is the one that I'm redirecting the user to it, but not after that.
This is the code:
ClaimsIdentity ident = await UserManager.CreateIdentityAsync(Login,
DefaultAuthenticationTypes.ApplicationCookie);
AuthManager.SignOut();
AuthManager.SignIn(new AuthenticationProperties
{
IsPersistent = true
}, ident);
HttpContext.Session["var"] = "data";
return RedirectToAction("Index", "Home");
I have tried the following steps so far:
I have manually added
Session
in theweb.config
[1].I have set
runAllManagedModulesForAllRequests
totrue
.- I have checked browser's cookie, it's being transmitted and it's the same during different requests.
- I have checked
Session.SessionId
and it's identical during different requests in current Session.
This is web.config
, it didn't have anything related to sessions and I added them manually.
<system.webServer>
<modules>
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</modules>
</system.webServer>
I'm trying to debug the app on IIS Express, and I haven't tried IIS yet.
I have access to the session variable in the account controller that takes care of the logging and Home controller which is where I redirect the user to, but not any other controller. I should note that if I refresh the page to hit the home controller for the second time, session variable is lost. In other words, they're not being preserved.
I just published the app and tried it on IIS, it seems to work fine there
Any possible solution and debugging guide is appreciated. :)