你总是可以使用catch的所有语法(我不知道名称是否合适)。
路线: 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 EXPRES Casinni运行不支撑Server.Transfer方法
请看一看这个小手册:MVC .Net Routing](http://stackoverflow.com/questions/379558/mvcnet-routing#379823),部分**选项3 ** - 它描述了如何构建自定义请求处理链。 – maxnk 2008-12-22 06:34:18