Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Help Page as default route

I have a C# .Net 4.5 Web Api application to which I have added a Help Page such as the one shown here.

When a developer launches the Web Api application in Visual Studio, I would like the help page to come up.

I would like to accomplish this by the using routing (such as a change to WebApiConfig.cs or Global.asax.cs) as opposed to a setting in the project's properties.

In the WebApiConfig.cs file I tried adding the following -

config.Routes.MapHttpRoute("Default", "api/help");

That did not work. Does anyone know how to make this work? Thanks.

like image 709
A Bogus Avatar asked Mar 13 '15 18:03

A Bogus


People also ask

What are the 3 segments of the default route?

The Default route maps the first segment of a URL to a controller name, the second segment of a URL to a controller action, and the third segment to a parameter named id.

What is the default route template in Web API?

Web API uses URI as “DomainName/api/ControllerName/Id” by default where Id is the optional parameter. If we want to change the routing globally, then we have to change routing code in register Method in WebApiConfig.


1 Answers

Two years late, but for the benefit of Googlers like myself - A way to do it (based on this answer) is simply to modify the RegisterArea method in the HelpPageAreaRegistration.cs class in the HelpPage Area to contain a blank route. Example -

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "HelpPage_Default",
            "Help/{action}/{apiId}",
            new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });
        context.MapRoute(
            "Help Area",
            "",
            new { controller = "Help", action = "Index" });

        HelpPageConfig.Register(GlobalConfiguration.Configuration);
    }
like image 150
Parrybird Avatar answered Oct 02 '22 06:10

Parrybird