How to increase the maximum allowed URL length in ASP.NET

Posted on Wednesday, July 4, 2018 at 2:16 PM into code & gotcha by Steve Woods.
Roughly a 1 minute read.

I recently came across an issue when developing an application for a client which had a requirement that caused some extremely long length URLs to be generated.

Now ordinarily I'd argue that the URL routing should be looked at because URLs should be human friendly, not machine friendly but in this case it was a necessity and besides it wasn't a human-facing URL.

However, .NET has a default URL value set to 260 characters and any attempt to visit the URL in question generated the following issue:

Server Error In '/' Application.


The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

The Solution

It was quite a simply fix really, just a parameter added into web.config solved the problem:

<httpruntime targetframework="4.5.2" maxurllength="500" relaxedurltofilesystemmapping="true"></httpruntime>
;

Comments

Please consider what you post!
Chillax if you're angry.

RSS 2.0 Feed | Copyright © 1999 - 2018 Steve Woods, All Rights Reserved - Warning, may contain nuts.