Thursday, May 18, 2006

Rough day and conditional server side includes

My day began with a heavy rain. I don't like driving in the rain, mostly because I need better windshield wipers. While I was driving to work a car hit me on the back. It was only a few scratches but that made me moody.
I got to work and the morning passed without major events, just coding and reviewing.
The whole team was invited to a lunch out for our good performance so we decided to go for Japanese food.
When I read the menu I saw that most of the plates said "Entrees", except the Specials. Coming from a Latin culture, and read Latin as the Roman Empire official Language not as in Latin America, I thought, ok, entrees, that's French and means entrance, or as in Spanish, lets ask two and that's it because I'm not too hungry. Oh well, in the Anglosaxon culture an Entree is a main course dish and the waitress kept going for an hour that I had ordered two entrees and I replied that yes, that I wasn't too hungry...LOL main problem today was a broken code.
I think I blogged before about conditional includes in classic ASP.
This morning I had to add some code for my part of the project in a common file that is shared among several sites.

The code looked like this:

<% Select myReport
Case "Report1": %> <!--#include virtual='Report1.asp'-->
<% Case "Lizis_Report" %> <!--#include virtual='Lizis_Report.asp' -->
<% End Select %>

It was an innocent extra case in a conditional statement. The thing is, conditional includes doesn't work in ASP and I should have known better as I have read this article on 4GuysFromRolla

My innocent Lizis_Report.asp had functions with the same name and signature than the functions in Report1.asp so the original ones got overwritten. The reason: IIS processes SSI before it processes ASP code, so both files are included at the same time.

I came home decided to make a small test in PHP with Apache:
I created a mytest.php with the following content:

<?php if(false){ ?> <!--#include virtual='file1.shtml' --> <? } else{ ?> <!--#include virtual='file2.shtml' --> <? } ?>

After testing it the output to the browser is
<!--#include virtual='file1.shtml' -->

So I guess it works in Apache but IIS is kinda lazy...
I better go swimming for a while to burn out the two "Entrees" I ate today :-P

See you later!


Post a Comment

<< Home