AttributeRouting icon indicating copy to clipboard operation
AttributeRouting copied to clipboard

Route resolving with urlencoded forward slashes as parameter

Open Geronimo2013 opened this issue 12 years ago • 4 comments

Hello,

I'm developing a web api interface. Therefore I setup a HttpSelfHostServer and use attributerouting for route resolving. All works fine until I pass a parameter which contains a urlencoded forward slash. The request seems to be url decoded before routing rules are applied. Therefore routing the requests fail.

For last parameter on the URI I can workaround it by adding a catch all parameters like: [GET("Level1/{queryparameter1}/Level2/{*queryparameter2}")]

However for queryparameter1 I should also be able to pass a (url encoded) parameter value containing a forward slash.

I tried to implement a messagehandler to interfere with the automatically decoded parameters but this didn't work out.

For WCF there is a config setting to work around this:

Is there something simular available for ASP.NET web api?

Regards,

Jeroen

Geronimo2013 avatar Jun 17 '13 08:06 Geronimo2013

Jeroen, it seems your config setting example is missing.

pjklein avatar Jun 17 '13 17:06 pjklein

Hi, the config is there but is made invisible. This config setting is described here: http://msdn.microsoft.com/en-us/library/ee656542.aspx

Geronimo2013 avatar Jun 18 '13 07:06 Geronimo2013

Would you please explain the reason for the slash in queryparameter1?

pjklein avatar Jun 18 '13 17:06 pjklein

With the route in the example we navigate from entity 'queryparameter1' to a related entity 'queryparameter2'. The entities are both identified by an identification containing one or more forward slashes. So for instance 'auth://entity/1' This is url encoded but despite that causing problems when webapi / attributerouting determines the method for the route. Possibly because it url-decodes the url before processing.

Geronimo2013 avatar Jun 18 '13 18:06 Geronimo2013