Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 1.33 KB

butility.WebApi.md

File metadata and controls

43 lines (33 loc) · 1.33 KB

bUtility.WebApi

###Routing Configuration Global.asax

GlobalConfiguration.Configure((httpConfiguration) =>
{

    httpConfiguration.Routes.MapHttpRoute(
            name: "DefaultPage",
            routeTemplate: "",
            defaults: new { controller = "Index", action = "Get" }
        );

    //other routes
    //....


    //generic api routing
    httpConfiguration.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}"
        );

    //handles any other route
    httpConfiguration.Routes.MapHttpRoute(
        name: "Error404",
        routeTemplate: "{*url}",
        defaults: new { controller = "Index", action = "Get" }
    );

    //handles wrong urls & exceptions
    httpConfiguration.Services.Replace(typeof(IHttpControllerSelector), 
        new ControllerSelector(httpConfiguration, "Index", "GetSimple"));
    httpConfiguration.Services.Replace(typeof(IHttpActionSelector), 
        new ActionSelector( ()=> { return new IndexController();  }, 
        "GetSimple"));
});