2016-04-26 2 views
0
gefunden werden kann

Ich versuche, ein webapi+angularjs+mvc Projekt zu entwickeln .hier Sie meine apicontrollerDie api-Controller in mvc nicht

public class DefaultController : ApiController 
    { 
     testDBEntities a = new testDBEntities(); 

     public IEnumerable<City> Get() 
     { 
      return a.Cities; 
     } 
    } 

Hier sehen Sie die webapiconfig

public static class WebApiConfig 
    { 
     public static void Register(HttpConfiguration config) 
     { 
      config.MapHttpAttributeRoutes(); 

      config.Routes.MapHttpRoute(
       name: "DefaultApi", 
       routeTemplate: "api/{controller}/{id}", 
       defaults: new { id = RouteParameter.Optional } 
      ); 

     } 
    } 

Aber sehen kann, wenn Ich tippe dies: localhost:5411/api/default

Ich habe diesen Fehler:

GlobalConfiguration.Configure(WebApiConfig.Register) in your Global.asax.cs file 
The resource cannot be found. 

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /api/default 
+0

Welche Version von WebAPI registrieren verwenden Sie? –

+0

@AlexArt. Wie kann ich die Version finden? –

+0

Verwenden Sie immer {action} in Ihrem Routenpfad wie - routeTemplate: "api/{controller}/{action}/{id}". Wenn Sie nicht {action} angeben, können Sie nicht mehrere get-Methoden in Ihrem Controller haben –

Antwort

2

die Zeile hinzufügen und dies wird die WebAPI Routen

+0

WebApi hat 'Startup.cs' anstelle von' global.asax.cs' –

+0

@Alex, beim Erstellen eines neuen Projekts, wenn sowohl mvc als auch webapi ausgewählt ist, wird nur global.asax hinzugefügt, nicht Startup.cs –

+0

@AlexArt. Ich kann GlobalConfiguration.Configure (WebApiConfig.Register) in der startup.cs nicht finden –

Verwandte Themen