Sometimes I forget to squash caching on my JSON handlers and end up with odd runtime behavior, especially when using IE.
You can ensure that each request actually pulls data instead of hitting the cache by adding this to the top of a handler (.ashx) or in the page_load of a .aspx. Drop 'context.' for use in page_load.
context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
This is what the head of my JSON handlers typically look like:
public void ProcessRequest(HttpContext context)
{
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
context.Response.ContentType = "text/json";
Technorati tags:
C-Sharp,
ASP.NET,
CodeProject-Tip