[thelist] IIS/URLs: IIS Directory Querystring

Paul Cowan evolt at funkwit.com
Sun May 26 20:19:01 CDT 2002


Aaron Johnson wrote:

> -- Course, it looks fugly when you do this... using your tip, if I try
> to access a page, say /aaron.asp, which doesn't exist, IIS will then
> redirect to
>
> /404.asp?404;http://myserver/aaron.asp
>
> Fugly.

Not really. Under IIS 5, this is done with a server.transfer, =no redirect
sent to client browser (all just one request). Also, you CAN then change the
status so that it sends a 200 OK (or whatever it might be), as long as you
have response buffering on.

We have a setup whereby we have "virtual virtual directories", if you catch
what I mean.
So someone comes in to:
    http://somesite.com/someclient/smoof/bling.asp?page=bloop
That's a 404. IIS transfers to
    /errorhandler.asp
Errorhandler.asp parses the URL, and looks in the database to see if
"/someclient/" represents a valid sub-site. If no -> 404. If yes, it checks
if the file "/smoof/bling.asp" exists. If no -> 404. If yes -> transfers
there. And all with only one client request, one response to client, with
status 200.

It's actually a bit trickier than it sounds, because this is effectively a
way of running multiple sites (same code, TOTALLY different looks) off one
URL without having to create a crapload of virtual directories. So
errorhandler.asp needs to pass data to bling.asp. This is BLOODY DIFFICULT,
because you can't transfer with a querystring. It took a LONG time to work
out how to pass data - there is only one field in the "request" or
"response" collections which is read/write, so we stuffed data in there.
There are lots of read-only fields, and lots of write-only, but only one
read/write, so we can set it in errorhandler.asp and read it in bling.asp;
I'll tease you by not telling you which one. Hehe.

So our code is.. really quite complicated. But it works. And it's
fantastically effective - we can create new sites without having to create
new virtual directories in IIS (doing this programmatically is not without
its own problems).

And to save the time of anyone who's thinking of trying this: if you have
problems that you can't work out, check if the "Check If File Exists" option
is set in the IIS configuration for the .asp extension. If it is not, things
will screw up. Badly.

But yeah, it can be done.

Paul





More information about the thelist mailing list