Web API 2 Attribute Routing - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Web API 2 Attribute Routing

  • Web API 2 Attribute Routing
  • I'm trying to use an Web Api Controller that has Route Attributes, but I'm unable to get it working.



    when the site is initializing causes it to stay on the loading page forever. I don't see any errors being thrown, so it's hard to determine where it's going wrong.

    Has anyone been able to get Route Attributes working?

  • In case anyone else runs into this problem, here's the solution I found:

    I noticed that though there were no errors being logged, the loading screen was making a failed request to


    The error message from the request was this:

        <Message>An error has occurred.</Message>
            The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.
        at System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() at System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)


    After the code registering the Routes, I added the line 


    and the site loaded and the Route Attributes were working again.