Monday, April 18, 2005

Trials and Tribulations ...

... with SSI development resolved.

Whew, nothing like a little back-of-the-envelope note-taking to help solve a problem. On the way home on Friday I was thinking more about the issues I had been experiencing in trying to get the suvey code to work regardless of whether the use accesses HTML- or ASP-based pages. I came up with a pretty good solution. It's a little bit of hackery, but we take what we can get sometimes.

Now in addition to the #exec SSI directive for HTML-based pages I have added some ASP code which executes the survey script in the case of the user accessing an ASP-based page. A liberal dose of commenting helps ensure that the browser doesn't display any of the underlying code and mess things up. Here's what's in the menu include file:
<!--#exec cgi="/includes/surveypage.asp"-->
<!--
<%Server.Execute("/includes/surveypage.asp")%>
<!-- -->
The ASP file also needed a minor modificaiton, I added an open/close comment block at the top of the output. A little more detail ...

In the case of HTML-based pages we need to use the #exec SSI directive to execute the survey script. In the case of ASP-based pages the #exec is worthless and so we add an ASP block that uses the Server.Execute statement to execute the survey script. On an HTML-based page the ASP code is sent to the browser and shows up as regular text. The comment tags surrounding the code ensuring that the browser does not display it.

On ASP-based pages, the #exec is sent to the browser as-is and treated as a comment block. The ASP code executes and displays the survey. I included the comment tags at the top of the ASP output so that the initial comment block is closed. This ensures that the survey is not contained inside a comment block (which would defeat the purpose of all this hackery). The extra comment open tag on the inlude file ensures that the closing comment tag at the end of the code block isn't orphaned when a user accesses an ASP-based page. An orphaned closing comment tag would be interpreted as regular text by the browser. Since you can put just about anything inside a comment tag the extra opening tags don't break the code.

One note, before just trying a good ol' ASP delimeters I had tried the <script runat="server"> </script> method of running the ASP. This doesn't work very well. The output is placed at the very bottom of the document and not inline where the script tags are located. I'm not sure if this is due to a combination of factors affecting this particular usage or because it's the default output method for script tags. Either way it's something to keep in mind for future development.