views:

361

answers:

4

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?

+4  A: 

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>
Thomas
Can't do inline script. Pages are marked CompilationMode="Never".
frankadelic
@frankadelic - But isn't the only reason they are marked with CompilationMode=Never in order to try to solve this refresh issue with include files?
Thomas
No, that's actually a design decision we made in this application.The ASPX files are published from a back-end system, and we have to use CompilationMode="Never" to prevent recompilations... because that will cause the App Domain to restart, HttpRuntime.Cache to be flushed, etc... http://dotnetslackers.com/ASP_NET/re-666_ASP_NET_2_0_No_Compile_Pages.aspx
frankadelic
@frankadelic - If you use Response.WriteFile, it will not cause a recompilation if the include file does not contain compilable stuff. If the include file does compilable stuff, then using an include file is not the right approach. A user/system control, declared statically or loaded dynamically solves the recompilation issue, will likely be faster and will put to rest any caching issues (server-side at least).
Thomas
+3  A: 

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

WinnerWinnerChickenDinner
Not so sure it has to do with compilation. Example: if I create an .aspx page with header CompilationMode="Never", ASP.NET will update the page if I modify HTML within the aspx... No compilation is even happening, yet the page is updated.....anyways, the gist of my question is, how to get the changes reflected when I open the page in a browser... whether it be caching, compilation, or some other factor.
frankadelic
@frankadelic: Updated above.
WinnerWinnerChickenDinner
+1  A: 

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 :-)

ZXX
+1  A: 

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"-->
Andrew Lewis
this might work, but defeats the purpose of an include file... since I would need to update every page that references the include file.
frankadelic