0

I'm using attribute routing and am having this controller with two Get-methods.

When requesting any of these two Get methods I get 404 back and I don't understand why since I've followed this guide from Microsoft (especially this part).

This is how the Controller looks like:

[RoutePrefix("api/rolesubscriptions")]
public class RoleSubscriptionsController : ApiController
{
    Route("roles")]
    public async Task<IHttpActionResult> GetRoles()
    { 
    }

    [Route("tags")]
    public async Task<IHttpActionResult> GetTags()
    {            
    }
}

And this is my WebApiConfig.cs file

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

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

Now based on this configuration I think that I would be able to do these requests

/api/rolesubscriptions/roles

and

/api/rolesubscriptions/tags

But both these requests return 404. Any help to help solve my problem is very appreciated.

EDIT 1 This is how my Application_Start() looks like

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
}

The Startup class exists but doesn't have any code that has to do with routing, only authentication.

public void Configuration(IAppBuilder app)
{
    app.UseCors(CorsOptions.AllowAll);
    // Authenication code omitted
}
Andreas
  • 2,336
  • 2
  • 28
  • 45
  • Your problem lies elsewhere. Where are you deploying your API? Can you add the complete endpoint you are trying? Also, it may be useful if you post your bootstrapping file (`Startup.cs` and/or `global.asax`) and your `Web.config`. – Federico Dipuma Jun 02 '16 at 09:53
  • I get these issues every now and again. Usually what fixes it, is a rinse an repeat of Clean -> Rebuild -> Build of about 30 times. In the browser each time you do it, do a clear cache reload and test it out. I was stuck for 2 hours with some routes not working. I didn't change a thing, but just build -> rebuild and then it started working again. I also refreshed the app pools. – Callum Linington Jun 02 '16 at 10:46
  • @FedericoDipuma added information! What part of web.config are you interested in? – Andreas Jun 02 '16 at 11:35
  • The modules part. Another question, did you register any area in MVC? – Federico Dipuma Jun 02 '16 at 12:28

0 Answers0