0

Obviously I am doing somethign wrong. Hence this question.

I have a MVC5 asp.net c# web app.

I have created an Area called 'Admin' in my solutions.

I have added an api controller class to my Controllers folder.

I have added a method inside it.

I have added a route to this method.

When I use a browser (in the actual server) to test this I get an error saying not found.

This is what I type in my browser:

https://my domain/Admin/Plan/List

This is the api class:

[RoutePrefix("Admin")]
public class StripeController : ApiController
{
    [HttpGet]
    [Route("/Plan/List")]
    public string List()
    {
       //return something
    }
}

I have found a similar question on SO here:

similar

but as i can see i have implemented this?

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Community
  • 1
  • 1
Andrew Simpson
  • 6,883
  • 11
  • 79
  • 179

1 Answers1

0

Try registering your areas after your have configured routing, e.g. change your Application_Start() to be:

protected void Application_Start()
{
    GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    AreaRegistration.RegisterAllAreas();
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

Presuming you are calling MapMvcAttributeRoutes() in your RouteConfig class.

Chris Pickford
  • 8,642
  • 5
  • 42
  • 73
  • thanks for that suggestion. I tried it and did not work I am afraid. And yes, I have MapMvcAttributeRoutes() in my RouteConfig class. But the more relevant thing to do is to put config.MapHttpAttributeRoutes(); in my WebApiConfig class which I have done – Andrew Simpson Feb 18 '16 at 10:10