Ehsan Akbar
Ehsan Akbar

Reputation: 7281

The api controller in mvc can't be found

I am trying to develop a webapi+angularjs+mvc project .here you can see my apicontroller

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

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

Here you can see the 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 }
            );

        }
    }

But when i type this : localhost:5411/api/default

i got this error :

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

Upvotes: 0

Views: 1115

Answers (1)

Karthik M R
Karthik M R

Reputation: 990

Add the line

GlobalConfiguration.Configure(WebApiConfig.Register) in your Global.asax.cs file

And this will register the webapi routes

Upvotes: 2

Related Questions