IIS httpErrors ExecuteURL appends weird query string like 500;http://thesite.com/failed-page to the target URL

iisiis-7.5

I've noticed weird behavior in IIS error pages. I've got this setup:

<httpErrors errorMode="Custom" existingResponse="Replace">
 <remove statusCode="500" />
  <error statusCode="500" responseMode="ExecuteURL" path="/error-page" />
</httpErrors>

Sometimes when an ASP.NET error occurs due to the query string being too long, then immediately the second error occurs while trying to execute the error page URL. I've tracked the problem to the fact that IIS appends the original url to the error page url like:

Original: http://example.com/someurl?id=some_very_long_query_string_causing_security_exception
Error: /error-page?500;http://example.com/someurl?id=some_very_long_query_string_causing_security_exception

This is a huge problem. If the original url fails for having a query string too long then the error page with the the appended stuff fails as well because it has a query string that is even longer!

I believe this is the dumbest bug in IIS. Does anyone know if there was some patch of service pack for that? Worst case scenario if nothing is fixed by now, is there a way to disable this behavior or any tricks to stop IIS appending unsolicited stuff to the error page? Because it breaks the whole custom error page mechanism.

Best Answer

Adding a trailing slash to the path (e.g. path="/error-page/") will stop the error code and URL being appended, note that it will keep the original failing URL, e.g.