1

次のような URL を処理するにはどうすればよいですか。

{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
        );
    }

上記のような定義を使用すると、既定のアクションがAsExcelになるように、 ExportControllerに別のルートを使用できます。

あなたが説明したルートの場合、エリアがMVCパターンの一部であるかどうかはわかりません。

それでも価値があるので、複雑なルートを持つこのスレッド ASP.Net MVCからいくつかの利点があるかもしれません - How to keep it "sane"?

于 2012-11-16T16:47:10.293 に答える