ASP.Net MVC route mapping

前端 未结 5 1803
独厮守ぢ
独厮守ぢ 2021-01-11 10:19

I\'m new to MVC (and ASP.Net routing). I\'m trying to map *.aspx to a controller called PageController.

routes.MapRoute(
   \"Pa         


        
5条回答
  •  说谎
    说谎 (楼主)
    2021-01-11 11:04

    public class AspxRouteConstraint : IRouteConstraint
    {
        #region IRouteConstraint Members
    
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            return values["aspx"].ToString().EndsWith(".aspx");
        }
    
        #endregion
    }
    

    register the route for all aspx

      routes.MapRoute("all", 
                    "{*aspx}",//catch all url 
                    new { Controller = "Page", Action = "index" }, 
                    new AspxRouteConstraint() //return true when the url is end with ".aspx"
                   );
    

    And you can test the routes by MvcRouteVisualizer

提交回复
热议问题