tags:

views:

45

answers:

2

Had a question from a client which stumped me.

They are using IIS 6.0 and for some reason, instead of making a normal request for a page on their server which I'll call www.domain.com/Default.aspx someone typed www.domain.com/Default.aspx/randomstuff

It seems that IIS's response was to serve Default.aspx as normal, but, as far as the browser is concerned, the path is www.domain.com/Default.aspx/ rather than www.domain.com/ and thus all relative paths to CSS, images, etc. fail

I looked at the traffic in Fiddler, and it seems that all of those image etc. requests, such as www.domain.com/Default.aspx/images/image.gif are ALSO returning the contents of Default.aspx, needless to say, not a valid image!

I don't believe they are doing anything special with URL rewriting, but just to be sure, I tried an experiment on a freshly created ASP.NET web application and the results were the same.

So what is causing IIS to pass a URL like /Default.aspx/randomstuff to the ASP.NET pipeline as a request for Default.aspx? And can it be stopped, and made to just throw a 404 as you'd expect?

+2  A: 

This is called the PathInfo component.

You can stop like this:

if (!String.IsNullOrEmpty(Request.PathInfo)) throw new HttpException(404);
SLaks
Also see the comment regarding "Check that file exists" in IIS at the bottom of the MSDN article.
Michael Stum
A: 

Yes, that's perfectly normal. Apache will do it too.

You can use it for routing, so you can have the URL /script.name/random/stuff instead of /script.name?page=random&section=stuff without having to set up URL rewriting.

Naturally the browser doesn't know that script.name is the real script, that random and stuff aren't really part of the path at the server-side. So all URLs will be relative to the random directory. Normally when you are writing an application with routing, you have to make sure you use rooted or absolute URLs through rather than relative URLs, for this reason.

And can it be stopped, and made to just throw a 404 as you'd expect?

Yes, as in SLaks's answer. However it would probably be better to send a 301 to the real address without the trailing Path Info parts.

bobince