Last post Mar 06, 2012 01:28 PM by anoopkp10
Feb 21, 2012 01:37 PM|anoopkp10|LINK
How to cache asmx/js call? I tried with HTTPModule and implemented caching . But this cache value is expiring during next login. It is reset to one year back of the last modified date. Through code I am not doing that.Is there any default setting
in asmx for doing that? If so ,is there a way to override the setting?
Feb 21, 2012 03:06 PM|muhammad fakhr elden sami|LINK
if you use Get method for requesting, request response will be returned
without call the service as it is cached in the browser history it self. when requests change, the call will reach the service.
Feb 21, 2012 03:09 PM|muhammad fakhr elden sami|LINK
This will help you how to write that
Feb 22, 2012 05:05 AM|anoopkp10|LINK
Actually my requirement is to cache this call (GetMygrid.asmx/js) in browser cache for some days and to avoid 304 response. I am able to cache this call using HTTPModule.
private void EndRequest(object sender, EventArgs e)
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
var path = context.Request.Path.ToLower().Replace('\\', '/');
if (path.EndsWith("/js") || path.EndsWith("/jsdebug") )
var lastModified = DateTime.UtcNow;
var expires = lastModified + TimeSpan.FromDays(5);
This code works fine during runtime while I am accessing the specific page many times. (GetMygrid.asmx/js) I am not getting 304 response while accessing the page and getting the following cache header.
Expires: Mon, 27 Feb 2012 04:52:11 GMT
Last-Modified: Wed, 22 Feb 2012 04:52:11 GMT
But my problem is when I login next time in app, this cache expires and value changes to one year back.I am using GET method for this call.
Expires: Mon, 21 Feb 2011 15:35:48 GMT
Last-Modified: Wed, 22 Feb 2012 04:39:37 GMT
So on next hit I am getting 304 for the same request.Is there a way to avoid that.
Feb 24, 2012 07:59 AM|Otomii Lu - MSFT|LINK
As far as I Know, this should not happen.
Try to debug your HTTPModule when you login for the second time,
to make sure EndRequest is executed and the Expires header has the correct value.
Mar 01, 2012 04:57 PM|javajunky|LINK
I am seeing the exact same behaviour after a move to ASP.NET 4 (on IIS 7). Do you by any chance use Spring.Net ?
Edit: Ignore me, this is how I would expect Asp.Net to work (now I've delved into it) be aware that the call to .SetExpires in the above code sample will silently fail on the first call into the module as (it turns out) you can only call 'SetExpires' on
a HttpCachePolicy that hasn't already had that header set (unless you want to set an expires that is older than the current one, apparently that works) .
Mar 06, 2012 01:28 PM|anoopkp10|LINK
My issue solved with the below code change to the above code
Thanks for the replies