asp.net mvc - Can I limit page number using MVC routing? -


my urls this:

/category/page-#  /tag/product/page-#  ...... 

can use mvc routing limit page number? want someting this:

routes.maproute(   name: "limitpaging",   url: "*/page-{pagenumber}",   defaults: new { controller = "error", action = "p404", },              new { pagenumber = @"\d+" },              new { pagenumber > 200 } ); 

thanks

your create custom route constraint (a class implements irouteconstraint)

public class lessthanpage : irouteconstraint {   private int _maxpage;    public lessthanpage(int maxpage)   {     _maxpage = maxpage;   }    public bool match(httpcontextbase httpcontext, route route, string parametername, routevaluedictionary values, routedirection routedirection)   {     return convert.toint32(values[parametername].tostring()) <= _maxpage;   } }  routes.maproute(   name: "limitpaging",   url: "*/page-{pagenumber}",   defaults: new { controller = "error", action = "p404", },    constraints: new { pagenumber > new lessthanpage(200) } ); 

you use method validate parameter number , therefore delete regular expression constraint


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -