简体   繁体   English

在IIS上运行的Web应用程序缓存数据库数据

[英]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.

相关问题 在本地(脱机)和没有IIS运行Web应用程序 - Running Web Application Locally (Offline) & without IIS 在 IIS 上启动 .NET Core Web API 时出错:“应用程序正在 IIS 进程内运行,但未配置为使用 IIS 服务器” - Error on starting .NET Core Web API on IIS: "Application is running inside IIS process but is not configured to use IIS server" 运行 exe 的 ASP.NET Web 应用程序在 VS 中工作,而不是在 IIS 中 - ASP.NET Web application running an exe works in VS, not in IIS 运行 razor 托管页面,blazor web 程序集,IIS 上的应用程序 10 - Running razor pages hosted, blazor web assembly, application on IIS 10 “ Web未在IIS中标记为应用程序” - “The Web is not marked as an application in IIS” Web应用程序表单将数据插入数据库 - web application form insert data into database 以编程方式将Web应用程序导入IIS - Import a web application to IIS programmatically 访问IIS上托管的Web应用程序 - Accessing web application hosted on IIS 在 IIS 上运行的 Web 应用程序不会在移动设备上的 Chrome 和 Safari 上将 HTTP 重定向到 HTTPS - Web Application Running on IIS Won't Redirect HTTP to HTTPS on Chrome and Safari on Mobile Devices 在本地IIS服务器上运行DotNet Core Web应用程序的正确安装顺序是什么? - What is the correct order of installation for running a DotNet Core web application on a local IIS server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM