locked
URI path great than 260 characters yeilds Bad Request RRS feed

  • Question

  • I am aware that by default HTTP.sys restricts path segments to 260 characters.

    And I know that this can be changed in HKLM\SYSTEM\CurrentControlSet\Services\HTTP\Parameters with DWORD value UrlSegmentMaxLength.

    But I have written a server and have it running on Windows Server 2008 and Vista Home Premium and when the path is longer than 260 characters, I get Bad Request. The longest segment is around 200 characters.

    I have even tried changing UrlSegmentMaxLength, but to no avail.

    It is absolutely essential that I be able to handle longer paths than this - the server encodes information into the id of a resource and this information can be very long.

    Why is the full path limited to 260 characters and what can I do to change it?
    Thursday, August 13, 2009 5:45 PM

Answers

  • You are right that the limit is a byproduct of the max path length in Windows (the max path length is 260, not 255)

    But HTTP.SYS is happy to handle much larger pathnames, which it does and hands them to IIS. It is IIS that falters when it tries to map the URL to a physical path even before calling my application. My application is more than happy to accept and path of arbitrary length.

    But IIS7 has a simple solution!

    With the URL Rewrite module you can replace the long url with a short one (or even an empty one) before it is processed by other parts of the IIS pipeline. The original URL (big pathname and all) is stored in a setting that is easily read.

    The URL Rewrite Module does not exist in the IIS Manager by default and must be downloaded. You can get it here: http://www.iis.net/extensions/URLRewrite

    The documentation is straight forward and explains how to set up the URL Rewrite. While they have examples of the use of this feature, overcoming the 260 character limit is not mentioned. In my mind it is one of the most important benefits.

    The following link shows how to handle long pathnames (see the last entry in the thread) http://stackoverflow.com/questions/1185739/asp-net-mvc-url-routing-maximum-path-url-length


    I don't know if there is a similar work-around for earlier versions if IIS.
    • Marked as answer by grsuggitt Monday, August 17, 2009 5:35 PM
    Monday, August 17, 2009 5:35 PM

All replies

  • In windows, path lengths are limited to 255 characters, that is why the Uri path lengths (which most often, map to filesystem paths) are limited as well.

    You should figure out a way of encoding the information in the entity body, using POST method. The best way to do this is to user WebClient class.

    feroze.

    Visit my blogs at:

    http://ferozedaud.blogspot.com
    http://blogs.msdn.com/feroze_daud
    Saturday, August 15, 2009 3:06 AM
  • You are right that the limit is a byproduct of the max path length in Windows (the max path length is 260, not 255)

    But HTTP.SYS is happy to handle much larger pathnames, which it does and hands them to IIS. It is IIS that falters when it tries to map the URL to a physical path even before calling my application. My application is more than happy to accept and path of arbitrary length.

    But IIS7 has a simple solution!

    With the URL Rewrite module you can replace the long url with a short one (or even an empty one) before it is processed by other parts of the IIS pipeline. The original URL (big pathname and all) is stored in a setting that is easily read.

    The URL Rewrite Module does not exist in the IIS Manager by default and must be downloaded. You can get it here: http://www.iis.net/extensions/URLRewrite

    The documentation is straight forward and explains how to set up the URL Rewrite. While they have examples of the use of this feature, overcoming the 260 character limit is not mentioned. In my mind it is one of the most important benefits.

    The following link shows how to handle long pathnames (see the last entry in the thread) http://stackoverflow.com/questions/1185739/asp-net-mvc-url-routing-maximum-path-url-length


    I don't know if there is a similar work-around for earlier versions if IIS.
    • Marked as answer by grsuggitt Monday, August 17, 2009 5:35 PM
    Monday, August 17, 2009 5:35 PM
  • Maybe the problem is as simple that:

    Http.sys service is coded with default of 260 Chars per Url Segment.

    It can be changed with Registry settings (Exemple for 4096 length) :

     

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters]

    "UrlSegmentMaxLength"=dword:00001000

     

    More about http.sys settings :

    http://support.microsoft.com/kb/820129

     

    It worked for me

    Wednesday, October 19, 2011 7:13 AM
  • I have IIS 7 which runx in 64 bit windows server 2008

    I am openning [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters]

    I right click on parameters select new dword 32 bit value I name it to

     MaxFieldLength (I select hexadecimal) enter fffe which is 0x0000fffe (65534)

    MaxRequestBytes  (I select hexadecimal) enter 1000000 which is 0x0000fffe (16777216)

    UrlSegmentMaxLength  (I select hexadecimal) enter fffe which is 0x001fffff (2097151)

    as it is in image https://dl.dropbox.com/u/541519/fb/reg.png

    I restart the server and still I only see up to 260 characters. What am i doing wrong

    I have also opened iis to set request filtering to correct values (query string ->enable settings 2097151 for max url length, max query string)

    I have a wcf running with web.config as

      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxUrlLength="32766" maxQueryStringLength="2097151" maxRequestLength="2097151" requestValidationMode="2.0" relaxedUrlToFileSystemMapping="true" />
        <customErrors mode="Off"/>
      </system.web>

    how did you manage to make this work????

    Regards,

    Wednesday, September 19, 2012 3:52 PM