I'm using Session in my application to store some data like user name(to write hello,...) and so on. Also, I'm using FormsAuthentication to authenticate user, so controllers have code like this:
protected void SetAuthCookie(int userId)
{
FormsAuthentication.SetAuthCookie(userId.ToString(), true);
User user = Repositories.UserRepository.GetUserById(userId);
Session["name"] = user.Name;
Session["email"] = user.Email;
Session["balance"] = user.TotalBalance + " / " + user.ActiveBalance;
Session["isConfirmed"] = user.IsConfirmed;
Session["phone"] = user.Phone;
}
So, when I restart application after some code changes session data is destroyed, but user is still authenticated, so I have very bad situation and I want to fix it. On the one hand, I can create code somewhere, that will check if session data is ok and refresh it otherwise. On the other hand, may I miss some technique of storing this data in the right way?
What is the best solution in this situation?
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
inProc, it would be destroyed when you recycle the applicationpool, which happens when you either update the web.config or rebuild (deploying new assemblies).