AttributeRouting
AttributeRouting copied to clipboard
Call to GetRouteData Blows up
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 ?
Curious, what method are you using to replace the HttpControllerDispatcher?
http://aspnetwebstack.codeplex.com/workitem/574
Web hosted routes use IRouteConstraint. Self hosted routes use IHttpRouteConstraint.
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??
That's what's in there. What are you looking for?
Just trying to Generate IHttpRouteData from a Url How can you do that?
So this is another problem that will have to wait for web api vnext. Sorry. :(