In order to make web sites manageable, using some sort of include file processing is usually used. IIS is configured to support include processing (Server Side Includes or SSI) for ASP, ASP.NET, .SHTM and .SHTML files, but it is not configured by default to process include files on .HTML or .HTM files. This article is a summary of how to configure IIS to support include processing for those file types.
The Internet Information Services Microsoft Management Console can be run using the Start menu:
Start-> Control Panel -> Administrative Tools -> Internet Information Services
The command line listed below will also launch the IIS MSC.
IIS MMC console:
To configure the IIS Web Site Mappings:
- Using the IIS MMC
- Select the Web Site to configure.
- Right click, select properties.
- Select the Home Directory tab.
- Select the configuration option
Web Site Properties
Add Extension Mappings
If server side includes are configured when IIS is setup, the file extension types .shtm and .shtml are configured in IIS to parse and process any #include statements. This same extension mapping needs to be completed for .htm and .html file types.
If you look at .htm and .html file types, you can see that processing is enabled on the GET and POST verbs. To add and configure an extension mapping for .htm and .html files, from the Mappings tab:
- Select Add
- Press Browse and go to the location in %SystemRoot%\System32\Inetsrv
- Select the ssinc.dll and press open to use this executable
- In Extension, add .htm
- In Verbs, select Limit to: GET, POST
- Press OK
- Perform the same steps for .html files.
Samples Using #includes
Within a valid HTML document, when you utilize #include directives, all the contents of the included file will be placed in the file when it is processed by IIS. An example #include directive:
<!-- #include file="Include.Header.inc.htm" -->
<!-- #include virtual="/Path/Include.Header.inc.htm" -->
Example contents of "Include.Header.inc.htm"
<!-- Header Begin -->
<div class="BannerPanel" id="BannerPanel">
<a href="/" title="TSI Systems LLC. Home">TSI Systems LLC.</a>
<!-- Header End -->
If you are using a UNIX / Linux based or Apache system, you will need to create a .htaccess file and place the following contents in it:
AddType text/x-server-parsed-html .html AddType text/x-server-parsed-html .htm
The configuration changes described here apply to both IIS 6 on Windows XP and Windows 2003 Server.
Turning on .htm processing slows down IIS to some degree so if you are including large files you may want to evaluate the impact to performance.
File types for .SHTM and .SHTML are more industry standard for include processing, but the Windows XP, Office and Visual Studio systems do not come configured by default to have Open / Edit handlers from the file system so I prefer the .htm extension for include processing.
I often use a naming convention "Include.Name.inc.htm" to help clearly indicate this file is a file included from other .htm files. Visual studio will complain with validation errors that these HTML snippets or included files are not a valid HTML or XHTML document (which they are not, they are only snippets to be included into other files).
ASP and ASP.NET could file types could be used for #include processing as well. However in my experience, if the only goal is managing #include processing and no other server side logic needs to be performed, it is much faster to have .htm #include processing and to not incur the overhead of ASP.NET compiling the application each time it gets removed from the application pool. I know there are strategies to deal with making ASP.NET 2.0 sites "pre-compiled" and to place them into application pools other than the default application pool, but I believe that is emphasizing the point I'm trying to make. Why add additional overhead in deployment headaches if it's not really necessary.
If you are hosting with an external hosting services, most web hosting providers either allow you to configure your hosting environment to turn on #include processing, or they will do it under a change or support request.
Lastly, using #include processing on a site gives one a little more flexibility in moving from a Windows hosted server to a Linux / Unix based or Apache server if needed. While for the most part ASP and ASP.NET based #include processing schemes require a Windows host.