C# ASP MVC 3自定义路由

C# ASP MVC 3自定义路由,c#,asp.net-mvc,model-view-controller,C#,Asp.net Mvc,Model View Controller,我如何处理这样的url: {subdomain}.{domainname}/{areas}/{controller}/{action} 例如:user1.contoso.com/Manage/User/View 我希望它是路线: {area} = Manage {controller} = User {action} = View {username} = user1 // View action parameter 任何帮助都将不胜感激:-)通常路由在方法注册表中的文件Global.asa

我如何处理这样的url:

{subdomain}.{domainname}/{areas}/{controller}/{action}
例如:
user1.contoso.com/Manage/User/View

我希望它是路线:

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

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

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

 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模式的一部分

不管它值多少钱,您可能会从这个线程中获得一些好处

通常,路由在方法注册表中的文件Global.asax中定义

 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模式的一部分

不管它值多少钱,您可能会从这个线程中获得一些好处

我不确定你怎么能按照你所描述的去做{subdomain}。您能否给出一个具体的例子,说明如何处理url
surya.google.com/export/file/sheetwork
,从而将
surya
作为参数来处理?@dtryon AFAIK子域应该在服务器上使用url重写来处理,而不是在应用程序上,因为服务器的任务实际上是将客户端重定向到正确的子域。这里讨论的内容可能有助于以所需的方式使用常规路由。我不确定如何按照您描述的方式到达{subdomain}。您能否给出一个具体的例子,说明如何处理url
surya.google.com/export/file/sheetwork
,从而将
surya
作为参数来处理?@dtryon AFAIK子域应该在服务器上使用url重写来处理,而不是在应用程序上,因为服务器的任务实际上是将客户端重定向到正确的子域。这里讨论的内容可能有助于以必要的方式使用常规路由