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:
Controllers
folder, Add Controller named TestController
.Write the following action in the TestController:
public IEnumerable<string> GetTestData()
{
return new[] { "A", "B", "C" };
}
Build, Run.
/api/test
Get error 404 The resource cannot be found.
/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.
Microsoft.AspNet.WebApi.HelpPage
nuget package.AreaRegistration.RegisterAllAreas();
to Global.asax.cs
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?
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:
Comment out the "[assembly: WebActivator.PreApplicationStartMethod" calls in the config files under App_Start folder.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With