4
I’m having problems with IIS cache (I think the problem is he), whenever I make any changes in the database, changes do not happen on the website, keeps the old data.
Changes only appear when I turn off and on IIS.
Attempts
I added this command to web.config
<caching enabled="false" />
In the controller, I also added this Annotation
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
And finally, in the global.asax
added this method
protected void Application_BeginRequest()
{
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
}
None of these attempts worked, maybe the problem isn’t cache, I don’t know...
Controller
public class CursosController : Controller
{
private SiteContext db = new SiteContext();
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult Index(Cursos curso)
{
return View(curso);
}
}
Leonardo, I believe that disabling the
Cache
is not the best way, I imagine some more problem of structure of your project.– Pablo Tondolo de Vargas
If possible, share your code
controller
.– Pablo Tondolo de Vargas
@Pablovargas I added the code of
controller
.– Leonardo
Try to use
[OutputCache(Location = OutputCacheLocation.None)]
– Pablo Tondolo de Vargas
Why not seek the courses within the method
Index
?– Marllon Nasser
@Marllonnasser Good question, I didn’t even realize that he passes the Courses to Index
– Pablo Tondolo de Vargas
@Pablovargas didn’t work out using this code you sent.
– Leonardo
Change your Index not to receive the Courses but to search in the bank before the return, being able to stay like this
public ActionResult Index()
 {
 return View(db.Cursos.ToList());
 }
– Pablo Tondolo de Vargas
@Marllonnasser I’m passing the
Curso
viaMvcRouteHandler.GetHttpHandler
. I’ll change and try to search through theIndex
.– Leonardo
@Pablovargas in fact in
Index
I will need to receive a parameter viaGET
, because I will show a single course.site.com/curso/administracao
– Leonardo
get the course data in real time... that is, before going to the view, fetch the database data for the course you want and then throw the filled object from the bank to the view.
– Marllon Nasser
Man, this happened to me a few times already. I always thought it was something from the other side because I never saw anyone complain about it. I am waiting for an answer and also an explanation for this to happen.
– Jéf Bueno
Then do the following in your index
public ActionResult Index(int id) { return View(db.Cursos.FirstOrDefault(a=>a.Id == id)); }
– Pablo Tondolo de Vargas
@Pablovargas It worked, the changes are being displayed correctly. I changed the logic and query is being made only in the controller.
– Leonardo
@jbueno I was able to solve my problem by only changing the place where the database query is being made.
– Leonardo
@Leonardo I don’t understand. It’s an example?
– Jéf Bueno
I think the answer is up to you to publish it yourself. Explain well what you did to fix your problem
– Pablo Tondolo de Vargas
@Pablovargas Okay. As soon as I have a little time I’ll draft an answer!
– Leonardo