views:

223

answers:

0

Hello,

I have ASP.NET MVC 1.0 application (.NET 3.5) running on II7 in 'Integrated Pipeline' mode. To cache/expire content, OutputCacheAttribute can be used to cache the action method's output. OutputCacheAttribute will send same output next time the action method is requested AND set response headers.

Please tell, how do I expire content on browser without using OutputCacheAttribute.

One option is to create a filter:

   public class ExpireContentAttribute : ActionFilterAttribute {
        public int Duration { get; set; }
        public override void OnResultExecuted(ResultExecutedContext filterContext) {
            if (Duration > 0) {
                filterContext.HttpContext.Response.Expires = 0;
                filterContext.HttpContext.Response.Cache.SetNoStore();
                filterContext.HttpContext.Response.AppendHeader("Pragma", "no-cache");
            }
        }
    }

then use filter in Controller:

public class SomeController : Controller {
    [ExpireContent(Duration=10)]
    public ActionResult Index() { 
      //do stuff
      return View(); 
      }
    }

Please advise.

Thank You.