How to update #include files - they are cached on IIS7 / ASP.NET

I have an ASP.NET main page that links to the #include file as follows:

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

I changed the file /includes/scripts.inc, but the changes do not appear on the pages. What needs to be done so that the changes are reflected?

I need to avoid the following:

  • server reboot
  • IIS reboot
  • modifying web.config (doesn't seem to have any effect)
  • almost everything that forces the application domain to restart

Any other options? Is there a parameter that affects how long IIS caches #include files?

+6
include iis-7 server-side-includes
source share
4 answers

First, as you probably know, you should not use the #include directive with ASP.NET. The correct solution is to use a user or server control. However, if you want you to add a bunch of HTML and Javascript to the page (i.e. server code), you can use Response.WriteFile:

 <%@ Page Language="vb"%> <html> <body> <% Response.WriteFile( "scripts.inc" ) %> </body> </html> 
+4
source share

It has nothing to do with caching, whether server-side or client-side. This is a compilation problem. #include does not appear as a change in ASP.NET when changing, so the page does not rebuild.

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

+3
source share

As long as it is truly static, just load the file into C # code and enter it yourself. then put it in a file dependent cache, and the object will change to null after changing the file, which will provide you with a flag to read it again.

If this is not static, enable (static == no ASP.NET control - it can be very mutable otherwise - like an eruption from a database or other CSS for a very user), then you want to ruin the compilation of the page, and this will not happen if you don’t go in and write your own template processor or anything else :-)

+2
source share

If you cache files that you might need to modify, you must specify the version number in the file name.

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

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

 <!--#include virtual="/includes/scripts-2.0.inc"--> 
+1
source share

All Articles