Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the WebAPI HelpPage package to work with the HotTowel template?

I am trying out the new Hot Towel template from John Papa. It is really slick, but I'm having some difficulties getting it to cooperate with what I'm used to for Web API.

I was able to work around a routing issue, but I still can't get the Microsoft.AspNet.WebApi.HelpPage package to work.

Here's what I have done:

  • Install the Hot Towel VSIX.
  • New ASP.NET MVC4 Projct - Hot Towel SPA Template
  • Build, Run - Works.
  • Right-Click Controllers folder, Add Controller named TestController.
  • Choose "Empty API Controller" template.
  • Write the following action in the TestController:

    public IEnumerable<string> GetTestData()
    {
         return new[] { "A", "B", "C" };
    }
    
  • Build, Run.

  • Try URL /api/test Get error 404 The resource cannot be found.
  • Try URL /api/test/gettestdata. Works.

Then I noticed that BreezeWebApiConfig.cs has changed the default api route, and the {action} is required, so I added the default api route back in:

GlobalConfiguration.Configuration.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
    );

Now when I try URL /api/test, it works.

Now I'd like to use the help package.

  • Add Microsoft.AspNet.WebApi.HelpPage nuget package.
  • Add AreaRegistration.RegisterAllAreas(); to Global.asax.cs
  • Build, Run.

When I try to the URL /Help, I get the following error:

System.InvalidOperationException: The view 'Index' or its master was not found
or no view engine supports the searched locations.
The following locations were searched:
    ~/Views/Help/Index.aspx
    ~/Views/Help/Index.ascx
    ~/Views/Shared/Index.aspx
    ~/Views/Shared/Index.ascx
    ~/Views/Help/Index.cshtml
    ~/Views/Help/Index.vbhtml
    ~/Views/Shared/Index.cshtml
    ~/Views/Shared/Index.vbhtml

What is the correct way to resolve this error without breaking the HotTowel template?

Should either of these be considered bugs?

like image 221
Matt Johnson-Pint Avatar asked Dec 15 '22 13:12

Matt Johnson-Pint


1 Answers

After installing the HotTowel template and and creating the application and then installing the HelpPage, I registered the help page area like below:

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

But doing so above caused the routetable routes to be in the following order and was noticing similar problems as you mentioned.

a.Breeze Api route
b.HotTowel route
c.Help page route
d.ignored routes
e.RouteConfig routes

So, i fixed the above order of routes by doing the following:

  1. Comment out the "[assembly: WebActivator.PreApplicationStartMethod" calls in the config files under App_Start folder.

  2. Register the routes in the following order in Global.asax.cs. This seems to have fixed the issue for me where i see the help page, invoke api routes and also see the home page accordingly.

    protected void Application_Start()
    {
        //help page
        AreaRegistration.RegisterAllAreas();
    
        //api
        BreezeWebApiConfig.RegisterBreezePreStart();
    
        //hot towel
        HotTowelRouteConfig.RegisterHotTowelPreStart();
    
        //register bundles
        HotTowelConfig.PreStart();
    
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    }
    
like image 83
Kiran Avatar answered Feb 23 '23 00:02

Kiran