mccalltd/AttributeRouting

NameBuilder internal route

Opened this issue · 2 comments

Hi

Running with a IAttributeRouteFactory, that'll add an extra 'internal' route for each route:

    public IEnumerable<IAttributeRoute> CreateAttributeRoutes(string url, IDictionary<string, object> defaults, IDictionary<string, object> constraints, IDictionary<string, object> dataTokens)
    {
        for (var n = 0; n != 2; ++n)
        {

            yield return new HttpAttributeRoute(n == 1 ? url : "internal/" + url,
                                                new HttpRouteValueDictionary(defaults),
                                                new HttpRouteValueDictionary(constraints),
                                                new HttpRouteValueDictionary(dataTokens),
                                                _configuration);
        }
    }

but how do I create a NameBuilder that returns two different names for the two different routes? .... don't seem to have the url (containing 'internal/') inside the NameBuilder function...

/Søren

Hmm, have you tried using a custom RouteNameBuilder delegate? See http://attributerouting.net/#route-names. Please clarify if I'm not understanding things.

Cheers

Yeah, that's what I'm doing.. but inside the RouteNameBuilder, how do I know if the route is an internal route or not... Ie. how do I distinct whether I have an 'internal/' route or not... The RouteSpecification doesn't seem to hold this info

What I'm trying to do, is to integrate AR with HyprLinkr (https://github.com/ploeh/Hyprlinkr) by implementing a IRouteDispatcher. However the IRouteDispatcher works on the RouteName, so I need to register the route, with a name I can re-create in the IRouteDispatcher, no problem.... The problem a raise when I have both an internal and a normal route for an endpoint, because I'd like HyprLinkr to return an internal Url if the request came via an internal url
For this I need to name the route based on whether it's internal or not.... however I can't seem to find a way to make this distinction within the IRouteNameBuilder...

I you were to pass in the routeUrl to the IRouteNameBuilder, then I'd be able to make this work....