いつでもキャッチオール構文を使用できます(名前が適切かどうかはわかりません)。
ルート:
routeTable.MapRoute(
"Path",
"{*path}",
new { controller = "Pages", action = "Path" });
コントローラー アクションは次のように定義されます。
public ActionResult Path(string path)
コントローラーのアクションにはパスがあるので、それをこぼして分析するだけです。
別のコントローラーを呼び出すには、 RedirectToAction を使用できます (これがより適切な方法だと思います)。リダイレクトを使用すると、永続的なリダイレクトを設定できます。または、次のようなものを使用します。
internal class MVCTransferResult : RedirectResult
{
public MVCTransferResult(string url) : base(url)
{
}
public MVCTransferResult(object routeValues)
: base(GetRouteURL(routeValues))
{
}
private static string GetRouteURL(object routeValues)
{
UrlHelper url = new UrlHelper(
new RequestContext(
new HttpContextWrapper(HttpContext.Current),
new RouteData()),
RouteTable.Routes);
return url.RouteUrl(routeValues);
}
public override void ExecuteResult(ControllerContext context)
{
var httpContext = HttpContext.Current;
// ASP.NET MVC 3.0
if (context.Controller.TempData != null &&
context.Controller.TempData.Count() > 0)
{
throw new ApplicationException(
"TempData won't work with Server.TransferRequest!");
}
// change to false to pass query string parameters
// if you have already processed them
httpContext.Server.TransferRequest(Url, true);
// ASP.NET MVC 2.0
//httpContext.RewritePath(Url, false);
//IHttpHandler httpHandler = new MvcHttpHandler();
//httpHandler.ProcessRequest(HttpContext.Current);
}
}
ただし、このメソッドは IIS で実行する必要があるか、IIS Express Casinni は Server.Transfer メソッドをサポートしていません。