mercredi 18 mai 2016

url of webapi, how to configure in mvc

I Have a url to a webapi, like this:"

and in the mvc project I have this files:

public class RouteConfig

        public static void RegisterRoutes(RouteCollection routes)

                name: "DefaultApi",
                url: "DefaultApi/{action}/{id}",
                defaults: new { controller = "Guestbook", action = "Index", id = UrlParameter.Optional, PageID = 1067 }


 public class WebApiConfig
        public static void Register(HttpConfiguration config)

            // Web API configuration and services

            // Web API routes

                name: "webapi/NavToDW",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }


and the Global.asax file:

public class Global : System.Web.HttpApplication
        public void Application_Start(object sender, EventArgs e)

            ViewEngines.Engines.Add(new Dynamicweb.AspNet.Views.RazorViewEngine());
            ViewEngines.Engines.Add(new Dynamicweb.AspNet.Views.WebFormViewEngine());
            // Fires when the application is started
            Dynamicweb.Frontend.GlobalAsaxHandler.Application_Start(sender, e);


        public void Session_Start(object sender, EventArgs e)
            // Fires when the session is started
            Dynamicweb.Frontend.GlobalAsaxHandler.Session_Start(sender, e);

        public void Application_BeginRequest(object sender, EventArgs e)
            // Fires at the beginning of each request
            //GlobalAsax.Application_BeginRequest(sender, e);

        public void Application_AuthenticateRequest(object sender, EventArgs e)
            // Fires upon attempting to authenticate the use
            Dynamicweb.Frontend.GlobalAsaxHandler.Application_AuthenticateRequest(sender, e);

        public void Application_Error(object sender, EventArgs e)
            // Fires when an error occurs
            Dynamicweb.Frontend.GlobalAsaxHandler.Application_Error(sender, e);

        public void Session_End(object sender, EventArgs e)
            // Fires when the session ends
            Dynamicweb.Frontend.GlobalAsaxHandler.Session_End(sender, e);

        public void Application_End(object sender, EventArgs e)
            // Fires when the application ends
            Dynamicweb.Frontend.GlobalAsaxHandler.Application_End(sender, e);

        public void Application_OnPreRequestHandlerExecute(object sender, EventArgs e)
            Dynamicweb.Frontend.GlobalAsaxHandler.Application_OnPreRequestHandlerExecute(sender, e);

So I can can connect. But I cant go to the specific link, like this:

the outcome is this:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<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.
bij System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() bij System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) bij System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)

So what I have to change?

Thank you

Aucun commentaire:

Enregistrer un commentaire