1

コントローラーを介して要求されたURLを処理できるようにしたい。

foo.com/a
foo.com/abcd
foo.com/x1

foo.com/aの場合

で処理したい

UrlHandlerControllerメソッド付きProcess(string url)

これを実行できるようにするには、ルーティングルールをどのように追加する必要がありますか?

何か案は?

4

2 に答える 2

4

新しいカスタムルートを作成し、PhillHaackのルートデバッガーを使用してルートをテストします。

routes.MapRoute(
    "customroute",
    "{url}", 
    new { controller = "UrlHandler",
        action = "Process",
        url = ""
    }
);

コントローラ:

public class UrlHandlerController : Controller
{
    [HttpGet]
    public ActionResult Process(string url)
    {
        return View();

        /* or */
        if(url == "something"){
            return View("SomethingView");
        }
        else if(url == "somethingelse"){
            return View("SomethingElseView");
        }
    }

}
于 2012-07-06T02:21:18.583 に答える
0

ダース、このルートが役立つかどうかを確認してください。

routes.MapRoute(
    "CustomRoute", // Route name
    "{url}", //Route formation
    new { controller = "UrlHandler", action = "Process" }, // Where to send it
    new { keyWord = @"\S+" } // Regex to identify the argument
);

よろしく。

于 2012-07-06T02:43:39.403 に答える