我想去http:// myserver并且能够获得帮助页面作为默认的主页,所以http:// myserver的第一件事就是帮助页面。
我有一个默认路由设置如下:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default",url: "{controller}/{action}/{id}",defaults: new { controller = "Home",action = "Index",id = UrlParameter.Optional } ); }
public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "HelpPage_Default","doc/{action}/{apiId}",new { controller = "Help",apiId = UrlParameter.Optional }); HelpPageConfig.Register(GlobalConfiguration.Configuration); }
当我将RouteConfig的控制器更改为“帮助”时,我得到:
The view ‘Index’ or its master was not found or no view engine
supports the searched locations
当我将帮助页面路由更改为“{controller} / {action} / {apiId}”时,我的AttributeRoutes停止工作。
解决方法
我用以下RouteConfig完成了这个。我也使用ASP.Net帮助页面从内联XML注释自动生成我的文档:
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // By default route the user to the Help area if accessing the base URI. routes.MapRoute( "Help Area","",action = "Index" } ).DataTokens = new RouteValueDictionary(new { area = "HelpPage" }); } }