应用程序根的默认路由

时间:2016-03-08 21:35:46

标签: asp.net asp.net-mvc routes url-routing asp.net-mvc-routing

如果我的awk ' NR == FNR {min[$1]=$4; next} { for (id in min) if ([id] = $5 && [id]) { print $0, id break } } ' file1 file2 - 应用程序在未指定的情况下指向特定的awk -v OFS='\t' 'NR==FNR{split($1,a,/[:-]/) rstart[a[1]]=a[2] rend[a[1]]=a[3] value[a[1]]=$2 next} $5~/unknown/ && $2>=rstart[$1] && $3<=rend[$1] {sub(/unknown/,value[$1],$5)}1' file1 file2 | column -t > output chr16 89985657 89986630 chr16:89985657-89986630 MC1R-2270|gc=63.5 chr16 89989779 89989898 chr16:89989779-89989898 unknown-2271|gc=73.9 chr16 89989779 89989898 chr16:89989779-89989898 TUBB3-2271|gc=73.9 chr16 89998969 89999097 chr16:89998969-89999097 unknown-2272|gc=57 chr16 89998969 89999097 chr16:89998969-89999097 TUBB3-2272|gc=57 chr16 89999866 89999996 chr16:89999866-89999996 unknown-2273|gc=55.4 chr16 89999866 89999996 chr16:89999866-89999996 TUBB3-2273|gc=55.4 chr16 90001127 90002222 chr16:90001127-90002222 unknown-2274|gc=63.9 chr16 90001127 90002222 chr16:90001127-90002222 TUBB3-2274|gc=63.9 chr17 1173848 1174575 chr17:1173848-1174575 BHLHA9-3|gc=78.7 mvc,该怎么说?

调试Controller时应该路由到Action

目前我有:

http://localhost:54500/

但这总是抛出

  

视图&#39;索引&#39;或者找不到它的主人,或者没有视图引擎支持搜索的位置

编辑#1

它应该重定向/路由到位于名为http://localhost:54500/Home/Index的{​​{1}}的视图。只是想澄清一下,routes.MapRoute( name: "Root", url: "", defaults: new { controller = "Home", action = "Index" } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { id = UrlParameter.Optional } ); Area都名为Home

该区域的配置为:

Controller

2 个答案:

答案 0 :(得分:4)

  

调试http://localhost:54500/时应该路由到http://localhost:54500/Home/Index

实际上,您配置它的方式,http://localhost:54500/将路由到HomeController.Index方法,而不是其他网址。

  

视图&#39;索引&#39;或者找不到它的主人,或者没有视图引擎支持搜索的位置

此错误表示路由成功,但控制器返回了不存在的视图的路径。

由于您还提到您正在使用区域并已发布您的配置,因此很明显发生了什么。您的配置按以下顺序运行:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Home_default",
        "Home/{controller}/{action}/{id}",
        new {action = "Index", id = UrlParameter.Optional}
        );
}

routes.MapRoute(
    name: "Root",
    url: "",
    defaults: new { controller = "Home", action = "Index" }
    );

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { id = UrlParameter.Optional }
    );

因此,如果您传递了网址http://localhost:54500/,则区域路线将会错过(因为它不会以/Home开头)并且它将与Root路线匹配。此Root路由不会路由到您的区域。有两种方法可以解决这个问题。

选项1 - 将根路由添加到主区

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Root",
        "",
        new { controller = "Home", action = "Index" }
        );

    context.MapRoute(
        "Home_default",
        "Home/{controller}/{action}/{id}",
        new {action = "Index", id = UrlParameter.Optional}
        );
}

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { id = UrlParameter.Optional }
    );

选项2 - 设置DataToken以指示主区

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Home_default",
        "Home/{controller}/{action}/{id}",
        new {action = "Index", id = UrlParameter.Optional}
        );
}

routes.MapRoute(
    name: "Root",
    url: "",
    defaults: new { controller = "Home", action = "Index" }
    ).DataTokens["area"] = "Home";

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { id = UrlParameter.Optional }
    );

答案 1 :(得分:3)

在Core 1.0.1中,您可以在Startup.cs中执行此操作:

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "areaRoute",
                 template: "{area:exists}/{controller=Home}/{action=Index}");

                routes.MapRoute(
                    name: "default",
                   // template: "{controller=Home}/{action=Index}");
                   template: "{area=MyArea}/{controller=Home}/{action=Index}");
            });
        }