sparkyShorts
sparkyShorts

Reputation: 630

Web Api Help Page route

I was recently tasked with fixing one of our Help Pages that had gone down. I hadn't ever worked on one before, so I jumped in and started playing around with it. I noticed we had this route set up for the Help Page:

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

        HelpPageConfig.Register(GlobalConfiguration.Configuration);
    }

I compared it to another working Help Page route and found the url to be different. I changed the url to

"Help/{action}/{apiId}"

and it worked. I've done some research online (this helped) but still fail to understand why changing the url would make any difference on whether that page would be hit. It would make sense to me that if I went to mydomain.com/api/v1/Help that I would still hit the help page with the original url.

Thank you in advance.

Upvotes: 1

Views: 736

Answers (1)

Prashant
Prashant

Reputation: 460

Route what you have "api/v1/Help/{action}/{apiId}" this is wrong because format of the route should be [Controller]/[Action]/[Id] and your controller is Help not "api/v1" .

And to answer your question to "mydomain.com/api/v1/Help" this url hitting the help page, yes it will if you give "help/{action}/apidid" url in the route.

"api/v1" till here its your IIS virtual directory setup not a route in your application configuration.

Upvotes: 1

Related Questions