AttributeRouting icon indicating copy to clipboard operation
AttributeRouting copied to clipboard

Call to GetRouteData Blows up

Open jasmeetsangari opened this issue 12 years ago • 6 comments

Hi ,

I have the Site Hosted in IIS and I am wanting to generate the RouteData so I have the following

  public class CustomHttpControllerDispatcher : HttpControllerDispatcher
    {
        private HttpConfiguration _httpConfiguration;
        public CustomHttpControllerDispatcher(HttpConfiguration configuration)
            : base(configuration)
        {
            _httpConfiguration = configuration;
        }

        protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
           request.Properties.Remove(HttpPropertyKeys.HttpRouteDataKey);
            routeData = _httpConfiguration.Routes.GetRouteData(request);
            foreach (IHttpRoute route in _httpConfiguration.Routes)
            {
                try
                {
                    routeData = route.GetRouteData(HttpContext.Current.Request.ApplicationPath, request);
                }
                catch
                { }
                if (routeData != null)
                {
                    break;
                }
            }
            return base.SendAsync(request, cancellationToken);
        }
    }

The call to GetRouteData Blows up with the following error for a matching route of type AttributeRouting.Web.Http.Framework.HttpAttributeRoute

the constraint entry 'httpMethod' on the route with route template '..' must have a string value or be of a type which implements 'IHttpRouteConstraint'.

Can you take a look ?

jasmeetsangari avatar Dec 11 '12 00:12 jasmeetsangari

Curious, what method are you using to replace the HttpControllerDispatcher?

http://aspnetwebstack.codeplex.com/workitem/574

waynebrantley avatar Dec 11 '12 00:12 waynebrantley

Web hosted routes use IRouteConstraint. Self hosted routes use IHttpRouteConstraint.

mccalltd avatar Dec 11 '12 00:12 mccalltd

Looking at the Src

using System.Collections.Generic;
using System.Web.Http.Routing;
using AttributeRouting.Framework;
using AttributeRouting.Framework.Factories;
using AttributeRouting.Web.Http.Framework;

namespace AttributeRouting.Web.Http.WebHost.Framework.Factories
{
    internal class AttributeRouteFactory : IAttributeRouteFactory
    {
        private readonly HttpWebAttributeRoutingConfiguration _configuration;

        public AttributeRouteFactory(HttpWebAttributeRoutingConfiguration configuration)
        {
            _configuration = configuration;
        }

        public IEnumerable<IAttributeRoute> CreateAttributeRoutes(string url, IDictionary<string, object> defaults, IDictionary<string, object> constraints, IDictionary<string, object> dataTokens)
        {
            yield return new HttpAttributeRoute(url,
                                                new HttpRouteValueDictionary(defaults),
                                                new HttpRouteValueDictionary(constraints),
                                                new HttpRouteValueDictionary(dataTokens),
                                                _configuration);
        }
    }
}

and

/// <summary>
    /// Route to use for self-hosted Web API routes.
    /// </summary>
    public class HttpAttributeRoute : HttpRoute, IAttributeRoute
    {

Is this correct??

jasmeetsangari avatar Dec 11 '12 01:12 jasmeetsangari

That's what's in there. What are you looking for?

mccalltd avatar Dec 11 '12 01:12 mccalltd

Just trying to Generate IHttpRouteData from a Url How can you do that?

jasmeetsangari avatar Dec 11 '12 01:12 jasmeetsangari

So this is another problem that will have to wait for web api vnext. Sorry. :(

mccalltd avatar Feb 13 '13 22:02 mccalltd