Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh #include files - they are caching on IIS7 / ASP.NET

I have an ASP.NET master page which references a #include file as follows:

<!--#include virtual="/includes/scripts.inc"-->

I have modified the file /includes/scripts.inc but the changes do not show up in pages. What needs to be done so modifications will be reflected?

I need to avoid the following:

  • restarting the server
  • restarting IIS
  • modifying web.config (doesn't appear to have any effect)
  • pretty much anything that causes the app domain to restart

Any other options? Is there a setting which affects how long IIS caches #include files?

like image 902
frankadelic Avatar asked Jul 28 '10 19:07

frankadelic


4 Answers

First, as you probably know, you shouldn't use the #include directive with ASP.NET. The right solution is to use a user control or server control. However, if what you want is to inject a bunch of HTML and Javascript into a page (i.e. no server-side code), then you could use Response.WriteFile:

<%@ Page Language="vb"%>
<html>
<body>
    <% Response.WriteFile( "scripts.inc" ) %>
</body>
</html>
like image 73
Thomas Avatar answered Nov 14 '22 22:11

Thomas


So as long as it's really static include, just load the file in C# code and inject it yourself. then put it in the cache with file dependency and the object will turn null after you change the file which will provide you the flag to read it again.

If it's not really static include (static == no ASP.NET controls - it can be very changeable otherwise - like a spew from a DB or different CSS for very user ) then you want to mess with page compilation and that's not going to happen unless you go and write your own template processor or something :-)

like image 43
ZXX Avatar answered Nov 14 '22 22:11

ZXX


Doens't have anything to do with caching, either server-side or client-side. It's a compilation issue. #include isn't caught as a modification in ASP.NET when changed, so the page isn't rebuilt.

This KB should help: http://support.microsoft.com/kb/306575

like image 24
Stan Avatar answered Nov 14 '22 23:11

Stan


If you're caching files that might need to change, you should include a version number in the file name.

eg: <!--#include virtual="/includes/scripts-1.0.inc"-->

then when you need to make changes to it, update your include to:

<!--#include virtual="/includes/scripts-2.0.inc"-->
like image 37
Andrew Lewis Avatar answered Nov 14 '22 23:11

Andrew Lewis