ASP.NET introduces a new URI component to the equation: PathInfo. It's not very well known, possibly due to poor implementation and consequent lack of usefulness. However, it is important that you understand how it can affect you.
Browsers (and the System.Uri class) only split paths into two pieces: the path and the query string. ASP.NET, however, splits the path once again, into the Request.FilePath and the Request.PathInfo properties. In the following three urls, the page test.aspx is always successfully executed, even though
test.aspx is not immediately followed by a question mark. The string between "test.aspx" and "?" is stored in the Request.PathInfo property, and is
not
used when trying to find the appropriate .aspx file to execute.
Note: If you name a folder
folder.aspx and try to access a file inside it, ASP.NET will try to find the file folder.aspx, and a
404 will occur. From what I can tell (on IIS7), only the .aspx extension will cause this to occur. The actual parsing is done in native code (UnsafeIISMethods.MgdGetUriPath(this._context, out ptr, out num, includePathInfo)), so I can only guess by trial and error.
PathInfo
would
be a wonderful way to do simple URL rewriting, since it allows basic query strings to be easily reformatted as "virtual" folders and files. The first set of paths both cleaner and more SEO-friendly than the second.
Using Reqeust.PathInfo
- http://www.site.com/products.aspx/Wireless
- http://www.site.com/products.aspx/Bluetooth
- http://www.site.com/products.aspx/Cat6
- http://www.site.com/blog.aspx/5020/Firebug_Rated_Web_Developer_Tool_Of_The_Year
Using Request.QueryString
- http://www.site.com/products.aspx?category=Wireless
- http://www.site.com/products.aspx?category=Bluetooth
- http://www.site.com/products.aspx?category=Cat6
- http://www.site.com/blog.aspx?id=5020&title=Firebug_Rated_Web_Developer_Tool_Of_The_Year
Don't get your hopes up, though. ASP.NET rebases all paths relative to Request.FilePath, while the browser is expecting paths relative to Request.Path. Hyperlinks, CSS files, images, and script files will all be broken.
Side effects
Since PathInfo allows requests like
/UrlTests/content/pages/test.aspx/folder/file to still reach
test.aspx, most ASP.NET sites can be linked to in a manner that will cause all file references to break. In fact, if a user accidentally types or adds a "/" after any URL ending in .aspx, your site will fall apart. I want my web sites to look and act professional in all situations, so I'm not too fond of Request.PathInfo. However, you can circumvent this issue by using a good URL rewriting library and configuring it correctly.
Here are a few sites which break when accessed in this manner
Update Feb 9, 09: The following sites have been 'fixed' since the posting of this article