我要去http://myserver
并且能够得到Help Pages作为默认主页,所以 guest 的第一件事就是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", action = "Index", apiId = UrlParameter.Optional });
HelpPageConfig.Register(GlobalConfiguration.Configuration);
}
当我更改 RouteConfig 的
controller
至 "Help"
我得到:The view 'Index' or its master was not found or no view engine supports the searched locations
当我将帮助页面路由更改为
"{controller}/{action}/{apiId}"
时我的 AttributeRoutes 停止工作。是否有一些简单的方法可以使 ASP.NET 帮助页面成为默认主页?
最佳答案
我使用以下 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",
"",
new { controller = "Help", action = "Index" }
).DataTokens = new RouteValueDictionary(new { area = "HelpPage" });
}
}
我还应该提到我在这个类中没有任何其他路由,因为我单独在 API 方法上使用属性路由。
关于asp.net-mvc-4 - ASP.NET 帮助页面默认主页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18879027/