Can you help an asp.net idjit to get her old server side includes to work?
August 2, 2006 9:33 AM
Subscribe
How do I make server side includes practical in .aspx pages?
So, I am converting my basic .html template over to a .aspx page by request. I have much of the framework of the page in various includes that are held in a folder called includes on the main folder level. Every webpage in my site, regardless of what folder it is in or on what level it currently resides, references these files successfully. I have been unable to make these includes work in my new .aspx template unless they are in the same folder as the template. After doing some research, the only information I found told me that I can't have an .aspx file reference an include with a path that has to go to a level above - that an .aspx page can only include files in the same directory or in levels below. If this is true, I am going to have MANY repeats of these includes, we are talking over well over 40. This sort of defeats the purpose of includes. The techy guy sitting next to me says he can write a script to update these includes but why even have includes if this is possible, why not just run a script to update every page? All I know is this is beyond me and I am feeling pretty low about all of this.
posted by Foam Pants to computers & internet (3 comments total)
1 user marked this as a favorite
This is true by default is IIS, but can be shut off by enabling "Parent Paths" in the site's configuration. You can pull off old-school ASP style includes (e.g., <!--#include file="../includes/header.asp"-->), but the recommended approach is to make your includes into UserControls. A free copy of Visual Studio Express will be helpful if you decide to pursue that angle. You make a reference to the user control with a <%@ Register > tag at the top of the file and then include it later on down the page.
Alternatively, you could look at the MasterPage approach, where you can create a whole template (i.e., header, footer, whatever else) and just reference it in each content page. Done right, it's probably easier than includes.
posted by yerfatma at 10:29 AM on August 2, 2006