I have an issue in my application as it seems the user entity is being cached in the AccountController.
If I update my user and change anything in the entity and save, it seems to work as far as dataBase is concerned. I can immediately see the change in the database after I click the Save button.
I have an Edit User page and then also a page that lists all the users. After I edit the user and save, it returns to the listing page and there I can see the changes I made (working like it should using a different instance of the same service).
But when I logout and log back in I am still seeing the original values in the account controller. In our AccountController we have userService that we use to retrieve the userInfo:
private IUserService _userSvc;
public AccountController(IUserService userSvc)
{
_userSvc = userSvc;
}
Then in the Login method we use that service to get the user entity:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
var timeoutMinutes = 60;
if (!ModelState.IsValid)
{
return View(model);
}
Session["UserName"] = "Unknown User";
Logger.Instance.Info("Setting username to unknown user");
var msg = string.Empty;
var user = _userSvc.GetLoginUserData(model.Username, out msg);
foreach (MembershipProvider provider in Membership.Providers)
{
var username = user.USERNAME;
...
}
If I look at the usr entity (after logout, login) at this point it still has the original values and not the attributes that are in the database for this entry.
Here is my LogOff method where i clear the session etc..
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
FormsAuthentication.SignOut();
Session.Clear();
Session.Abandon();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
// clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
SessionStateSection sessionStateSection = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState");
HttpCookie cookie2 = new HttpCookie(sessionStateSection.CookieName, "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
return RedirectToAction("Login", "Account");
}
Why is the _userSvc caching the data and not showing what is in the database. If I stop Visual Studio and restart the debug then the entity has the correct data so it appears to be caching?
No where else in the app am I having this issue with entity Framework its only in the AccountController.Login that it appears to be caching the data.