日期:2014-05-17  浏览次数:20534 次

ASP.NET MVC 路由选择问题,大家各抒己见
我重写了IRouteHanlder, IHttpHandler, 但是MyHttpHanlder中的ProcessRequest方法就是不被触发。
public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //routes.MapRoute(
            //    "DefaultTT", // Route name
            //    "test", // URL with parameters
            //    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            //);

            RouteValueDictionary defaults = new RouteValueDictionary();
            RouteValueDictionary constraints = new RouteValueDictionary();
            RouteValueDictionary tokens = new RouteValueDictionary();

            defaults.Add("controller", "home");
            defaults.Add("action", "index");
            defaults.Add("data", string.Empty);
            constraints.Add("data", @"[a-zA-Z0-9\-]*");
            tokens.Add("pageId", 0);

            routes.Add(new Route("", defaults, constraints, tokens, new MyRouteHandler()));
        }

        protected void Application_Start()