【问题标题】:ASP.NET Help Pages default home page?ASP.NET Help Pages 默认主页?
【发布时间】:2013-09-23 14:44:06
【问题描述】:

我想去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", action = "Index", apiId = UrlParameter.Optional });

    HelpPageConfig.Register(GlobalConfiguration.Configuration);
}

当我将 RouteConfig 的 controller 更改为 "Help" 时,我得到:

未找到视图“索引”或其主视图或没有视图引擎 支持搜索位置

当我将帮助页面路由更改为 "{controller}/{action}/{apiId}" 时,我的 AttributeRoutes 停止工作。

有没有一些简单的方法可以让 ASP.NET 帮助页面成为默认主页?

【问题讨论】:

    标签: asp.net-mvc-4 asp.net-mvc-areas attributerouting asp.net-web-api-helppages


    【解决方案1】:

    我通过以下 RouteConfig 实现了这一点。我还使用 ASP.Net 帮助页面从内联 XML cmets 自动生成我的文档:

    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 方法上单独使用属性路由。

    【讨论】:

      【解决方案2】:

      对于那些搜索在哪里添加路由的人,使用当前版本的 WebApi 和 NuGet 包,您必须在 NuGet 添加的 Area 文件夹中搜索名为“HelpPageAreaRegistration”的文件。

      这是我的,一旦它被编码为使用 WebApi 的帮助页面具有默认网页。

      public class HelpPageAreaRegistration : AreaRegistration
      {
          public override string AreaName
          {
              get
              {
                  return "HelpPage";
              }
          }
      
          public override void RegisterArea(AreaRegistrationContext context)
          {
              context.MapRoute(
                  "HelpPage_Default",
                  "Help/{action}/{apiId}",
                  new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });
              context.MapRoute(
                  "Help Area",
                  "",
                  new { controller = "Help", action = "Index" }
                  );
              HelpPageConfig.Register(GlobalConfiguration.Configuration);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-01
        • 1970-01-01
        • 2012-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-18
        • 2015-11-18
        相关资源
        最近更新 更多