Attribut-Routing in WebAPI: Die Ressource kann Nicht Gefunden Werden
ASP.NET MVC4 Projekt mit WebAPI Endpunkte. Ich bin versucht zu konfigurieren AR für beide MVC-Controller und API-Controllern. Ich habe Folgendes:
Und jetzt sehe ich noch zwei weitere Dateien im App_Start: AttributeRoutingConfig, und AttributeRoutingHttpConfig.
Die erste ist diese:
[assembly: WebActivator.PreApplicationStartMethod(typeof(AttributeRoutingConfig), "Start")]
public static class AttributeRoutingConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
GlobalConfiguration.Configuration.Routes.MapHttpAttributeRoutes();
}
public static void Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
Das zweite ist dies:
[assembly: WebActivator.PreApplicationStartMethod(typeof(AttributeRoutingHttpConfig), "Start")]
public static class AttributeRoutingHttpConfig
{
public static void RegisterRoutes(HttpRouteCollection routes)
{
routes.MapHttpAttributeRoutes();
}
public static void Start()
{
RegisterRoutes(GlobalConfiguration.Configuration.Routes);
}
}
In meinem GlobalConfig habe ich dieses:
GlobalConfiguration.Configure(WebApiConfig.Register);
In meinem WebApiConfig habe ich dieses:
config.MapHttpAttributeRoutes();
Den Fehler bekomme ich wenn ich versuche zu POSTEN, um eine route eingerichtet mit [POST api ("/message")]:
The constraint entry 'inboundHttpMethod' on the route with route template 'api/message' must have a string value or be of a type which implements 'IHttpRouteConstraint'.
In mein Global.asax:
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
Was mache ich falsch?
InformationsquelleAutor RobVious | 2013-11-14
Du musst angemeldet sein, um einen Kommentar abzugeben.
Sie versuchen, zu kombinieren, Tim McCall ' s package + Web-API-2-built-in-Attribut-routing-Funktion. Installieren Sie nicht das Paket, wie seine bereits in Web-API-2-version.
Prüfen: http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
Recht, wenn Sie noch mit MVC4, Tim ' s package ist der Weg zu gehen...
Cool. Ich ersetzte meine Attribute mit [Route()] nach dem entfernen der WebApi-Paket und alles scheint ok - wenn es stinkt, kann ich nicht angeben, nicht mehr POSTEN
fügen Sie einfach HttpPost auf der Strecke: [Route(""), HttpPost()]
InformationsquelleAutor Kiran Challa