admin管理员组文章数量:1122832
I’m working on a .NET wcf application with ASPX pages. Every time I update the web.config file (such as changing versioning), I want to make sure that none of the pages are cached and are always reloaded with the updated version.
My Concerns:
Default Behavior: Are ASPX pages cached by default (either on the browser or server)?
Caching After Update: When I make changes to web.config, how can I ensure all pages always fetch the latest content and do not serve from cache?
Caching Control: What is the best way to completely disable caching for both browser and server-side caching in this scenario?
My Question:
How can I ensure no caching happens at all (both browser and server-side) after a web.config update, and how do I force a reload of the latest version of all pages?
I’m working on a .NET wcf application with ASPX pages. Every time I update the web.config file (such as changing versioning), I want to make sure that none of the pages are cached and are always reloaded with the updated version.
My Concerns:
Default Behavior: Are ASPX pages cached by default (either on the browser or server)?
Caching After Update: When I make changes to web.config, how can I ensure all pages always fetch the latest content and do not serve from cache?
Caching Control: What is the best way to completely disable caching for both browser and server-side caching in this scenario?
My Question:
How can I ensure no caching happens at all (both browser and server-side) after a web.config update, and how do I force a reload of the latest version of all pages?
1 Answer
Reset to default 0For web pages, not really an issue.
Are ASPX pages cached by default (either on the browser or server)?
No, server caching does not really occur, but this ASSUMES you take steps when updating the web site.
I mean, for a desktop program, you can’t update the program while it is running, and often .dll’s will be in memory and locked. That’s not called caching, that’s called locked .dll’s in memory!
So, updating web.config really has ZERO in regards to some web page (or code) being cached here. Two VERY different issues here.
To be fair, updating web.config will trigger an app pool re-start, and that will suffice for changes to web.config. However, updating site code and pages? That’s not related to updating web.config (they are only related since you often update some pages and often will have updated web.config during a new publish).
However, to be safe, I suggest stopping both app pool and the web server (not site) before any update, and thus this issue becomes a non issue. Of course, stopping the web server (from IIS), means that any site will be stopped.
The reason the above is suggested is of course is just like the above desktop example, then .dll’s (which is your code behind) can be locked in memory if in use. Hence, even a publish of the site without first stopping the web server (and app pool) from IIS manager? Then some code assets can be cached, but better stated, are locked in memory and “in use”. This is especially the case is the IIS server has multiple sites running, and shared library code is being used by several sites.
Note when I say stopping the web server, I mean stopping the given server from the IIS manager, not a stop of the whole windows server! However, to be fair, a full re-boot of the server not all that bad of a idea here!
While above solves any server side code and assets in memory sever side?
The VERY difficult issue of .css and script files being cached client side remains a problem and challenge.
Such assets (.css, and .js files) can be cached for months and even longer in client side browsers.
And updating such file assets on the server side DOES NOT update the client side. You do NOT have control over this issue – that process is based on client side browser side settings – settings you can’t control at all, end of story PERIOD! Those browsers are not your computer – hands off, you can’t touch the user’s computer!
There are 2 approaches often used here.
If you update a script library, or .css file, then ALSO change the file name used. This can be painful from a developer's point of view if lots of pages have script and .css referenced files. If possible, then put all such references in the "master" page if you have one. Thus only one "spot" in the site exists for such referenced files.
So, a rename is a sure fire way to ensure the new script (or .css) file is re-loaded by client browsers. However, such re-names can thus break pages that have such references (hence the advice to place such file references in as few places as possible - like the master page).
Another way, and often preferred is to simply add a “dummy” version number to such files. Thus, no re-name is required to trigger client browsers to re-load such assets.
Say you have this .js and .css file:
<link href="/Scripts/jquery.toast.min.css" rel="stylesheet" />
<script src="/Scripts/jquery.toast.min.js"></script>
And say you updated both of above? And did not change the file names?
To force client side browsers to see/use and download the new updated files?
You can add a "dummy" version number like this:
<link href="/Scripts/jquery.toast.min.css&ver=1.2" rel="stylesheet" />
<script src="/Scripts/jquery.toast.min.js&vers=1.2"></script>
And if you again update the above 2 files (.css and script), then simply increment the number from 1.2 to 1.3 and so on. However, if that site has many pages, and each page has such script file references? Then you need to update all such pages.
There are some "automated" 3rd party tools that can/will find all script and .css file references, and "increment" the ver (version) number for you on each deployment (publish). However, this feature is not part of nor built into Visual Studio.
本文标签: netHow Can I Ensure ASPX Pages Don’t Cache After webconfig Updates in ASPNET Web FormsStack Overflow
版权声明:本文标题:.net - How Can I Ensure ASPX Pages Don’t Cache After web.config Updates in ASP.NET Web Forms? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736282528a1926670.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论