C# ASP.NET SQL SERVER

ASP.NET MVC Output Caching

I've found what I believe to be a bug in ASP.NET MVC's caching model inasmuch as it appears to be caching GET's when caching is not specified. However, even though I think that it's a bug it's way more likely that this is something that I haven't understood or something that I've done wrong: The first rule of programming: It's my fault.

I've written a wizard style registration process for a site. It's fairly simple and stores the stage at which the user is at in a session state variable. Here is the code: 

[OutputCache(Duration=0, VaryByParam="None")]
public ActionResult Register()
{
    string registerStage = GetStage();

    switch (registerStage)
    {
        case "1":
            return View("Register1");
        case "2":
            return View("Register2", UserDetailsVM);
        case "3":
            return View("Register3", UserDetailsVM);
        case "4":
            return View("CancelClicked");
        default:
            return View("NotFound");
    }
}

What I found was that without the [OutputCache(Duration=0, VaryByParam="None")] attribute it appeared that the view was being cached.

If I removed this attribute and called the action via a browser it would work and break points inside the action would be hit the first time I navigated to the action/page. If I then navigated to a web form page (this is a hybrid web form / mvc application) and then returned to this page the Register action would not be hit. Added the [OutputCache(Duration=0,...] fixed the problem.

» Similar Posts

  1. Combine, compress, and update your CSS file in ASP.NET MVC
  2. Optimizing CSS in ASP.NET MVC
  3. Automatically keeping CSS file current on any web page

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback link for this post:
http://guyellisrocks.com/trackback.ashx?id=163

» Comments

  1. Bhavin avatar

    Really helpful and I found this after wasting 2 days behind this but worth it totally ... thanks and nice post...

    Bhavin

    Bhavin — August 26, 2011 1:19 PM
  2. Bhavin avatar

    Really helpful and I found this after wasting 2 days behind this but worth it totally ... thanks and nice post...

    Bhavin

    Bhavin — August 26, 2011 1:20 PM

» Leave a Comment