AttributeRouting icon indicating copy to clipboard operation
AttributeRouting copied to clipboard

prefix == url

Open smolesen opened this issue 12 years ago • 3 comments

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

smolesen avatar Mar 21 '13 07:03 smolesen

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

digiguru avatar Mar 21 '13 08:03 digiguru

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

smolesen avatar Mar 21 '13 09:03 smolesen

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]

mccalltd avatar Apr 19 '13 03:04 mccalltd