[英]Web application running on IIS caches database data
We have an application programmed with ASP.NET and C#. 我们有一个使用ASP.NET和C#编程的应用程序。 The application has users which can change their passwords.
该应用程序的用户可以更改其密码。 And there is our problem:
还有我们的问题:
When a user changes the password, the new password gets sent to the server and we save the new password in the code using EntityFramework: 当用户更改密码时,新密码将发送到服务器,并且我们使用EntityFramework将新密码保存在代码中:
var entry = this.dataContext.Entry(entity);
entry.State = EntityState.Modified;
this.dataContext.SaveChanges();
Anyway, when the user now tries to log in with the new password, he fails. 无论如何,当用户现在尝试使用新密码登录时,他将失败。 Instead, he still can log in with the old password.
相反,他仍然可以使用旧密码登录。
We know that the DatabaseContext still has the old data in it, but we don't know why, and how we can enforce it to load the new data after we saved the edited data. 我们知道DatabaseContext中仍然有旧数据,但是我们不知道为什么,以及保存保存已编辑的数据后如何执行它以加载新数据。 On the database, the new password gets saved.
在数据库上,将保存新密码。
LazyLoadingEnabled is set to false, if that helps. 如果有帮助,请将LazyLoadingEnabled设置为false。
Can anyone help us? 谁能帮助我们?
So, we solved the problem. 因此,我们解决了问题。
Basically the problem was that on application start, we opened a DbContext (1) and everytime someone logs in, the application took the user data from the same DbContext (1). 基本上,问题在于,在应用程序启动时,我们打开了一个DbContext(1),每次有人登录时,应用程序便从同一DbContext(1)中获取用户数据。 When the user changes his password, the application opens another DbContext (2) and changes it.
当用户更改密码时,应用程序将打开另一个DbContext(2)并进行更改。 As soon as you want to log in again, the application took the data from the old DbContext (1).
一旦您想再次登录,应用程序就会从旧的DbContext(1)中获取数据。 Since the DbContext gets never recreated in the whole runtime of the web application, the user data also gets never updated in the context.
由于从未在Web应用程序的整个运行时中重新创建DbContext,因此用户数据也永远不会在上下文中更新。
I hope this answer helps if anybody hits the same problem. 如果有人遇到相同的问题,我希望这个答案会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.