Disable IIS Caching

4

I'm having problems with IIS cache (I believe the problem is it) , whenever I make any changes to the database, the changes do not happen on the site, / p>

Changes only appear when I turn off and turn on IIS.

Attempts

I added this command in web.config

<caching enabled="false" />

In the controller, I also added this annotation

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]

And finally, in global.asax I 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 is not cache, I do not 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);
    }        
}
    
asked by anonymous 11.01.2017 / 14:49

1 answer

1

I changed my Controller to query the Course in the database, and not receive it from another place, like this:

public ActionResult Index(string parametro)
{
    var curso = db.Cursos.FirstOrDefault(x => x.Slug == parametro);
    if (curso == null)
    {
        return new HttpStatusCodeResult(HttpStatusCode.NotFound);
    }
    return View(curso);
}

Note that I'm now getting as a parameter a string and not a Curso , unlike what I was in the question. You also do not need to put the following annotation

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
    
11.01.2017 / 17:06