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.
Calling
GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
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
/appstatus?count=2
The error message from the request was this:
<
Error
>
<
Message
>An error has occurred.</
Message
>
<
ExceptionMessage
>
The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.
</
ExceptionMessage
>
<
ExceptionType
>System.InvalidOperationException</
ExceptionType
>
<
StackTrace
>
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)
</
StackTrace
>
</
Error
>
After the code registering the Routes, I added the line
GlobalConfiguration.Configuration.EnsureInitialized();
and the site loaded and the Route Attributes were working again.