这个问题并不是由于程序本身的问题导致的,而是由于重新加载网站时浏览器缓存的原因,可以在launchSettings.json文件中添加以下行来解决:
"iisSettings": { "applicationUrl": "http://localhost:5000/", "sslPort": 0 }, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "ASPNETCORE_URLS": "http://localhost:5000/" },
另外,也可以通过在Startup.cs文件中添加以下行来清除缓存:
app.Use(async (context, next) => { context.Response.Headers["Cache-Control"] = "no-cache, no-store, must-revalidate"; context.Response.Headers["Pragma"] = "no-cache"; context.Response.Headers["Expires"] = "-1"; await next(); });
这样做可以确保在重新加载网站时,浏览器不会使用缓存,而是从服务器下载最新的内容。