More in this section
Forums / Developing with Sitefinity / Web API 2 Attribute Routing

Web API 2 Attribute Routing

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 1 answered
  1. Chris
    Chris avatar
    0 posts
    Registered:
    08 Apr 2015
    17 Jan 2017
    Link to this post

    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?

    Answered
  2. Chris
    Chris avatar
    0 posts
    Registered:
    08 Apr 2015
    17 Jan 2017 in reply to Chris
    Link to this post

    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.

2 posts, 1 answered