UriTemplate and escaped '/'

Topics: ASP.NET Web API
May 13, 2012 at 12:52 AM

Hi,

Just in case this is indeed a problem and hasn't been fixed in post VS 11 RC builds...

I have a typical controller that looks like this...

/foo/{controller}/{id}

I get a 404 when I try an HTTP request against URIs such as...

http://localhost/foo/controller/bar%2Fsavas

I would very much like for the '/' to be part of my {id}.

I hope this helps.

Cheers,

.savas.

May 13, 2012 at 12:55 AM

It may be that ASP decodes it for us but we can have a look.

Henrik

May 13, 2012 at 1:00 AM

Thanks Henrik...

BTW... the same applies for an escaped "#".

.savas.

Coordinator
May 13, 2012 at 1:19 AM

Hi savas,

Can you try using this route instead:

/foo/{controller}/{*id}

Note that there's a "*" before the id parameter, which means to capture everything until the end of the path. We call it a catch-all parameter.

Hopefully that works for you!

Thanks,

Eilon

May 13, 2012 at 1:23 AM

Thanks Eilon,

This indeed works. Many thanks.

Unfortunately, though, my goal is to support URIs like this as well...

/foo/node/{id}
/foo/node/{id}/properties
/foo/node/{id}/relationships
/foo/node/{id}/latest
...

where {id} is an escaped URI.

Wouldn't {*id} prevent me from doing the above?

thanks,
.savas.