Mat*_*int 4 c# asp.net-mvc asp.net-web-api breeze hottowel
我正在试用John Papa 的新Hot Towel模板.它真的很光滑,但是我在使用它与我习惯的Web API合作时遇到了一些困难.
我能够解决路由问题,但我仍然无法使Microsoft.AspNet.WebApi.HelpPage包工作.
这就是我所做的:
Controllers文件夹,添加名为的控制器TestController.在TestController中编写以下操作:
public IEnumerable<string> GetTestData()
{
return new[] { "A", "B", "C" };
}
Run Code Online (Sandbox Code Playgroud)构建,运行.
/api/test获取错误404The resource cannot be found./api/test/gettestdata.作品.然后我注意到它BreezeWebApiConfig.cs已经改变了默认的api路由,并且{action}是必需的,所以我添加了默认的api路由:
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试URL时/api/test,它可以工作.
现在我想使用帮助包.
Microsoft.AspNet.WebApi.HelpPagenuget包.AreaRegistration.RegisterAllAreas();到Global.asax.cs当我尝试URL时/Help,我收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
在不破坏HotTowel模板的情况下解决此错误的正确方法是什么?
其中任何一个都应该被视为错误吗?
安装HotTowel模板并创建应用程序然后安装HelpPage后,我注册了以下帮助页面区域:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Run Code Online (Sandbox Code Playgroud)
但是上面这样做导致路由表路由按照以下顺序排列,并注意到你提到的类似问题.
a.Breeze Api route
b.HotTowel route
c.Help page route
d.ignored routes
e.RouteConfig routes
Run Code Online (Sandbox Code Playgroud)
所以,我通过执行以下操作修复了上述路线顺序:
在App_Start文件夹下的配置文件中注释掉"[assembly:WebActivator.PreApplicationStartMethod"].
在Global.asax.cs中按以下顺序注册路由.这似乎解决了我的问题,我看到帮助页面,调用api路由,并相应地看到主页.
protected void Application_Start()
{
//help page
AreaRegistration.RegisterAllAreas();
//api
BreezeWebApiConfig.RegisterBreezePreStart();
//hot towel
HotTowelRouteConfig.RegisterHotTowelPreStart();
//register bundles
HotTowelConfig.PreStart();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
}
Run Code Online (Sandbox Code Playgroud)