1

我如何处理这样的网址:

{subdomain}.{domainname}/{areas}/{controller}/{action}

例如:user1.contoso.com/Manage/User/View

我希望它是路线:

{area} = Manage
{controller} = User
{action} = View
{username} = user1 // View action parameter

任何帮助将不胜感激 :-)

4

1 回答 1

1

通常路由在文件Global.asax的方法 RegisterRoutes中定义

 public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


        routes.MapRoute(
            "Export",                                                            // Route name
            "Export/{action}/{table}",                                       // URL with parameters
            new { controller = "Export", action = "AsExcel", table = "" }  // Parameter defaults
        );

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );
    }

使用上面的定义,您可以为ExportController使用单独的路由,以便默认操作是AsExcel

在您所描述的路线的情况下,我不确定区域是否是 MVC 模式的一部分。

仍然物有所值,您可能会从这个线程 ASP.Net MVC 中获得一些好处,其中包含复杂的路由 - 如何保持“理智”?

于 2012-11-16T16:47:10.293 回答