3

My Route looks like:

config.Routes.MapHttpRoute(
     name: "DefaultApi",
     routeTemplate: "api/{controller}/{id}/{uri}",
     defaults: new { id = RouteParameter.Optional, uri = RouterParameter.Optional }
);

I have a Base64 encoded uri that I send in place of the {uri} parameter. It has no illegal characters (I've formatted it properly and checked to make sure). However, it's about 300-400 characters long.

When I send a DELETE request to this address using the long base64 parameter, I get a 400 BAD STATUS, INVALID URL response. When shortening the parameter, it works. I suspect that there is a max path problem?

Using a query string in place of a path parameter works, but I'd rather stay with the RESTful approach. Is there a config setting I can change on my Web API project to allow longer path-based parameters?

This works:

http://localhost:99999/api/reg/10?uri=<long_base64_parameter>

This does not work:

http://localhost:99999/api/reg/10/<long_base64_parameter>
j0k
  • 22,600
  • 28
  • 79
  • 90
Justin Skiles
  • 9,373
  • 6
  • 50
  • 61
  • How have you formatted it properly? – JayC Dec 09 '12 at 03:53
  • Did you use encodeURIComponent? https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIcomponent – JayC Dec 09 '12 at 03:55
  • @JayC Yes, illegal characters are replaced. I've checked the outgoing HttpRequest and confirmed that there are only alphanumeric characters in the parameter. Please note that my request works when using a query string but not when using a RESTful path parameter. – Justin Skiles Dec 09 '12 at 03:57

1 Answers1

1

Looks like these are related:

The request URL is invalid in IIS 7

ASP.NET MVC, Url Routing: Maximum Path (URL) Length

Also see:

http://social.msdn.microsoft.com/Forums/nl/netfxnetcom/thread/723e6bfd-cab7-417b-b487-67f1dcfa524f

Looks like there might be path segment restrictions by default, but there are several workarounds (url rewriting, registry changes, etc.)

Community
  • 1
  • 1
JayC
  • 7,053
  • 2
  • 25
  • 41
  • Thanks for the response. Unfortunately, I've been through all those links and the workarounds are not suitable for my problem. Altering the behavior of the web server is out of the question because it's hosted in Azure. – Justin Skiles Dec 09 '12 at 04:23
  • How so? Url Rewriting looks to be supported in Azure. http://msdn.microsoft.com/en-us/library/windowsazure/dd573358.aspx. All you'd need to do is add a few lines to your web config, I would hope. I've never used Azure services, but as long as the URL Rewrite module is installed in IIS for any cloud instance, adding rewrite rules for an application is generally as simple as modifying your application's web config file. – JayC Dec 09 '12 at 04:28