PathInfo Woes

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.
Request.RawUrl /UrlTests/content/pages/test.aspx/folder/file?querystring /UrlTests/content/pages/test.aspx/?querystring /UrlTests/content/pages/test.aspx?querystring
Request.FilePath /UrlTests/content/pages/test.aspx /UrlTests/content/pages/test.aspx /UrlTests/content/pages/test.aspx
Request.Path /UrlTests/content/pages/test.aspx/folder/file /UrlTests/content/pages/test.aspx/ /UrlTests/content/pages/test.aspx
Request.PathInfo /folder/file / (empty string)
Control.ResolveClientUrl("test.jpg") /UrlTests/content/pages/test.jpg /UrlTests/content/pages/test.jpg /UrlTests/content/pages/test.jpg
Control.ResolveUrl("test.jpg")(Improper path resolution) test.jpg test.jpg test.jpg
Relative path needed by browser ../../test.jpg ../test/jpg test.jpg
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


Using Request.QueryString

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

Published on

About Nathanael

Nathanael Jones is a software engineer, father, consultant, and computer linguist with unreasonably high expectations of inanimate objects. He refines .NET, ruby, and javascript libraries full-time at Imazen, but can often be found on stack overflow or participating in W3C community groups.


If you develop websites, and those websites have images, ImageResizer can make your life much eaiser. Find out more at


I run Imazen, a tiny software company that specializes in web-based image processing and other difficult engineering problems. I spend most of my time writing image-processing code in C#, web apps in Ruby, and documentation in Markdown. Check out some of my current projects.

More articles