AttributeRouting
AttributeRouting copied to clipboard
prefix == url
Hi If have the following controller:
[RoutePrefix("product")]
public class ValuesController : ApiController
{
[GET("product"), HttpGet]
public void GetByName(string name)
{
...
}
}
I would have expected to be able to reach it using:
~/product/product
however in RouteBuilder, you have the following code:
// Prepend prefix if available
if (routePrefixUrl.HasValue() && !routeSpec.IgnoreRoutePrefix)
{
var delimitedRoutePrefix = routePrefixUrl + "/";
if (!delimitedUrl.StartsWith(delimitedRoutePrefix))
{
delimitedUrl = delimitedRoutePrefix + delimitedUrl;
}
}
which doesn't add the prefix, if it the same as the routeUrl ... any specific reason for that??
/Søren
Isn't that code just removing the trailing slash if it already exists? Your route needs a {name:string} parameter — Sent from Mailbox for iPhone
On Thu, Mar 21, 2013 at 7:38 AM, smolesen [email protected] wrote:
Hi If have the following controller: [RoutePrefix("product")] public class ValuesController : ApiController { [GET("product"), HttpGet] public void GetByName(string name) { ... } } I would have expected to be able to reach it using: ~/product/product however in RouteBuilder, you have the following code: // Prepend prefix if available if (routePrefixUrl.HasValue() && !routeSpec.IgnoreRoutePrefix) { var delimitedRoutePrefix = routePrefixUrl + "/"; if (!delimitedUrl.StartsWith(delimitedRoutePrefix)) { delimitedUrl = delimitedRoutePrefix + delimitedUrl; } } which doesn't add the prefix, if it the same as the routeUrl ... any specific reason for that??
/Søren
Reply to this email directly or view it on GitHub: https://github.com/mccalltd/AttributeRouting/issues/229
No, it's saying that if route + '/' != prefix + '/' then route = prefix + route....
The service is called with product/product?name=1234567, so no need for the {name:string} parameter.
If I change it to:
[RoutePrefix("product/product")]
public class ValuesController : ApiController
{
[GET(""), HttpGet]
public void GetByName(string name)
{
...
}
[GET("product/smomethingelse", IgnoreroutePrefix=true), HttpGet]
public void GetBySomethingElse(string name)
{
...
}
}
then I'm able to use:
~/product/product?name?1234567 and ~/product/somethingelse?name=1234567
just seems a bit clumpsy....
/Søren
Yeah, there's some code to prevent unintentional duplicates. I didn't consider intentional duplicate url sections. As a temporary workaround, you could do:
[GET("product/product", IgnoreRoutePrefix = true), HttpGet]