Just a short, simple blog for Bob to share his thoughts.
28 December 2010 • by Bob • IIS
Many years ago I wrote Microsoft KB article 203064 about using Server-Side-Include (SSI) files with IIS 4 and IIS 5, but that KB has long since vanished from Microsoft's support website because it was never updated for IIS 6 or IIS 7. I eventually turned the information from that KB article into a blog post, but that being said, I still see questions about SSI showing up in the IIS forums every once in a while. There was a great deal of useful information in that KB article about general SSI syntax and several practical examples for SSI directives, so I thought that it would make a good blog post if I updated the information from that KB for later versions of IIS.
This blog post details some features that are available in the Microsoft implementation of Server-Side Include (SSI) files for Internet Information Server (IIS) and provides general syntax and examples for SSI directives.
SSI files are most commonly used with IIS to allow content authors to include the contents of one file inside another file, allowing the easy creation of script libraries or page headers and footers to standardize the look and feel of your web content. SSI consists of very simple commands that are contained within HTML comment tokens, and are limited in functionality. Higher-level programming languages like ASP, ASP.NET, PHP, etc. make the need for SSI considerably less necessary than in previous years. In addition, programming features such as ASP.NET's Master Pages and Dynamic Web Template (DWT) files that are used by Dreamweaver, Expression Web, and FrontPage have replaced much of the need for SSI. Because of this, SSI is an outdated technology by today's standards. With that in mind, web developers are highly encouraged to migrate their SSI content to another technology, such as ASP.NET or PHP.
SSI files are mapped by file extension to a preprocessor or handler dynamic-link library (DLL), in the same way that file like ASP, ASP.NET, PHP, etc. are mapped to their requisite handlers. In the case of SSI, the specific handler is ssiinc.dll for IIS 4 through IIS 6 and iis_ssi.dll for IIS 7. SSI files on Windows are often named with .stm file extensions, although extensions of .shtm and .shtml are also supported.
cmd
directive for #exec
is disabled by default in IIS 5 and IIS 6. To enable the cmd
directive, see Microsoft KB article 233969.cmd
directive for #exec
is now disabled for SSI files in IIS 7; you can only use the cgi
directive.SSI is employed by the use of special preprocessing directives in SSI documents that are contained within HTML comment tokens; these directives are parsed by the SSI DLL and processed into HTML that is returned to a web client. All SSI directives take the following general form:
<!--#<DIRECTIVE> [<PARAMETER> = <VALUE>]-->
IIS supports a small set of SSI directives, and each directive has different parameters that configure the output for the directive. Other web servers may support a different set of SSI directives and parameters, so SSI files are not 100% compatible across different technologies.
The following directives are supported in the IIS implementation of SSI:
<!-- #CONFIG <ERRMSG/TIMEFMT/SIZEFMT>="<format>" -->
<html> <body> <!-- #CONFIG TIMEFMT="%m/%d/%y" --> <p>Today's Date = <!--#ECHO VAR = "DATE_LOCAL" --></p> <!-- #CONFIG TIMEFMT="%A, %B %d, %Y" --> <p>Today's Date = <!--#ECHO VAR = "DATE_LOCAL" --></p> </body> </html>
<!--#ECHO VAR = "<CGI_VARIABLE_NAME>"-->
<html> <body> <p>Server Name = <!--#ECHO VAR = "SERVER_NAME"--></p> <p>Date = <!--#ECHO VAR = "DATE_LOCAL" --></p> <p>Page URL = <!--#ECHO VAR = "URL" --></p> </body> </html>
<!-- #EXEC <CGI/CMD>="<command>" -->
<html> <body> <p>Root Directory of C:</p> <pre><!--#EXEC CGI = "/cgi-bin/HelloWorld.exe" --></pre> </body> </html>
233969 SSIEnableCmdDirective is set to FALSE by default
<!--#FLASTMOD <FILE/VIRTUAL> = "filename.ext"-->
<html> <body> <!-- #CONFIG TIMEFMT="%m/%d/%y" --> <p>Modified Date = <!--#FLASTMOD FILE="filename.ext"--></p> <!-- #CONFIG TIMEFMT="%B %d, %Y" --> <p>Modified Date = <!--#FLASTMOD FILE="filename.ext"--></p> </body> </html>
<!--#FSIZE <FILE/VIRTUAL> = "filename.ext"-->
<html> <body> <!-- #CONFIG SIZEFMT="BYTES" --> <p>File Size = <!--#FSIZE FILE="filename.ext"--> bytes</p> <!-- #CONFIG SIZEFMT="ABBREV" --> <p>File Size = <!--#FSIZE FILE="filename.ext"--> KB</p> </body> </html>
<!--#INCLUDE <FILE/VIRTUAL> = "filename.ext"-->
<html> <body> <!--#INCLUDE FILE = "header.inc"--> <p>Hello World!</p> <!--#INCLUDE VIRTUAL = "/includes/footer.inc"--> </body> </html>
The #config directive supports a large array of possible parameter values, which are listed in the following table. Note: All of these values are case-sensitive.
Value | Description | Example |
---|---|---|
%A |
Full Weekday Name | Tuesday |
%a |
Short Weekday Name | Tue |
%B |
Full Month Name | December |
%b |
Short Month Name | Dec |
%c |
Full Date & Time | 12/28/10 19:52:19 |
%d |
Day of Month as a Number | 28 |
%H |
Hours as a Number on a 24-Hour Clock | 19 |
%I |
Hours as a Number on a 12-Hour Clock | 07 |
%j |
Julian Date (Offset from Start of Year) | 362 |
%M |
Minutes as a Number | 52 |
%m |
Month as a Number | 12 |
%p |
AM or PM Indicator | PM |
%S |
Seconds as a Number | 19 |
%U |
Week Number (Offset from Start of Year) | 52 |
%W |
Week Number (Offset from Start of Year) | 52 |
%w |
Day of the Week as a Number | 2 |
%X |
Short Time | 19:52:19 |
%x |
Short Date | 12/28/10 |
%Y |
Four-Digit Year as a Number | 2010 |
%y |
Two-Digit Year as a Number | 10 |
%Z |
Time Zone Name | Pacific Standard Time |
%z |
Time Zone Name | Pacific Standard Time |
Note: The following Windows Script Host (WSH) code will create a sample SSI page that you can use to test the parameter values for the #config directive:
Option Explicit
Dim objFSO, objFile, intCount
Set objFSO = WScript.CreateObject("Scripting.Filesystemobject")
Set objFile = objFSO.CreateTextFile("ssitest.stm")
objFile.WriteLine("<html>")
objFile.WriteLine("<body>")
For intCount = Asc("A") To Asc("Z")
objFile.WriteLine("<!-- #CONFIG TIMEFMT=""%" & _
UCase(Chr(intCount)) & """ --><p>%" & _
UCase(Chr(intCount)) & _
" = <!--#ECHO VAR = ""DATE_LOCAL"" --></p>")
objFile.WriteLine("<!-- #CONFIG TIMEFMT=""%" & _
LCase(Chr(intCount)) & """ --><p>%" & _
LCase(Chr(intCount)) & _
" = <!--#ECHO VAR = ""DATE_LOCAL"" --></p>")
Next
objFile.WriteLine("</body>")
objFile.WriteLine("</html>")
SSI directives that use file paths can reference files by using a file or virtual path.
<!--#include file="myfile.txt"-->
<!--#include virtual="/scripts/myfile.txt"-->
For additional information on using SSI with IIS, click the following article numbers to view the articles in the Microsoft Knowledge Base:
For more Microsoft Knowledge Base articles about using SSI with IIS, click here.
Note: This blog was originally posted at http://blogs.msdn.com/robert_mcmurray/