Last post Jun 03, 2008 08:48 PM by AndrewSeven
May 31, 2008 01:56 AM|rmadhu|LINK
I have a static HTML file. I need to localize the page. I could have created multiple html pages for different cultures - but the idea is not to create multiple versions of the HTML files (maintenance is an issue) and i'd like to leverage ASPX localization
facility to achieve this.
I've converted the HTML to an ASPX page with Server side HTML controls, and declarative localization with resource files in App_GlobalResources folder. The page take the culture as a query string parameter. The query string parameter is to enable the browser
to cache multiple versions of the page for different cultures. Localization is not based on the culture(language) setting in the browser. The UICulture of the thread is set explicitly based on the query string parameter.
To cut a long story short - i want to use ASPX localization facilities and i'd like the browser to treat the resultant pages like static pages, and i'd also want to use ASPX page output caching to cache the result for multiple cultures.
Localization is not an issue at all. Its the browser / page output caching that's the issue.
I would like the browser to cache the page, but send a request with the If-Modified-Since header on subsequent request and i would like ASPX page to send back a 304 status if the ASPX page or the resouces files that it depends on have not changed. I would
NOT like the browser to cache the page with an Expries/max-age attribute for any specified period of time - i would like it to request for the page everytime and let the server decide to send a 304 / new version of the page.
Looks simple enough - use <%@OutputCache %>, add file dependency using Response.AddFileDependency(), a varybyparam for ASPX output caching and ASPX sends back a Last-Modified header perfectly. It also handles 304s.
But here's the catch. We HAVE to specify a Duration attribute for the output cache. This results in a max-age/Expires headers in the response and consequently, the browser does not even request for the page subsequently (until the cache expires) - also
after the expiry ASPX sends out the whole content again (does not send 304).
The work around is probably to remove the <%@OutputCache %> directive, call Response.AddFileDependency() and Response.SetLastModifiedFromFileDependencies() [ideally SetETagFromFileDependencies as well] - the Last-Modified header goes fine. Also i'd have
to manually handle the If-Modified-Since request header myself to send 304's. This works fine too (but how do i handle ETags). And ASPX page output caching is now disabled - which defeats part of the purpose.
Is there a way to handle such a requirement in ASPX automatically - set File dependency such that ASPX sends Last-Modified / ETag header automatically, sets Expires/max-age header such that browser request for page everytime, ASPX sends 304s based on file
dependency and If-Modified-Since header, and also caches the output varied by param and sends from the caches if the request does not have a Last-Modified header?
In short can i tell ASPX to handle this page like a static page - but varied by param and varied by file dependency.
Or is this just wishful thinking on my part? Or am i missing something grossly ?
Sorry for such a long post.
May 31, 2008 07:36 AM|M imran shafiq|LINK
Please write short and briefly we cannot understand it...
Jun 03, 2008 08:48 PM|AndrewSeven|LINK
I don't think there is an automatic way to do it.
If I were you, I would start in the page, then try to move stuff to an http module or handler.
In an early event/method like oninit, check the file dependencies and if its still up to date, then send the 304 status and end the response, If they are expire, let the page process...