asp.net mvc - Creating custom URL routing that separates admin section from other sections of a website -
i'd create custom url routing has constant path @ asp.net mvc 5 project. illustration i'd have "www.mysite/admin/controller/action/" admin
constant.also have routes apart this.
after i'd define policy while entered admin/controller/action/
in browser, directed admin panel, else if admin/
not exist in url, directed regular page. goal, i've written codes in _viewstart.cshtml
needs reforms.
public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( name: "tag", url: "tags/{tag}/{page}/{id}", defaults: new { controller = "article", action = "index", tag = (string)null, id = urlparameter.optional, page = @"/d" } ); routes.maproute( name: "tags", url: "tags/", defaults: new { controller = "tag", action = "index" } ); routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); routes.maproute( null, "page{page}", new { controller = "article", action = "index" }, new { page = @"/d" } ); }
_viewstart.cshtml:
@{ if (httpcontext.current.user.isinrole("administrator")) { // ??? need codes directing /admin part layout = "~/views/shared/_adminlayout.cshtml"; } else { layout = "~/views/shared/_layout.cshtml"; } }
you utilize admin area in mvc application, , have it's own routing. take @ link here help using areas. route may this...
public override void registerarea(arearegistrationcontext context) { context.maproute( "admin_default", "admin/{controller}/{action}/{id}", new { action = "index", id = urlparameter.optional } ); }
asp.net-mvc url routes asp.net-mvc-5
No comments:
Post a Comment