I'd like to create a custom URL routing that has a constant path at ASP.NET MVC 5 project.
For example I'd like to have "www.mysite/admin/controller/action/" that admin
is a constant.Also I have some routes apart from this.
After that I'd like to define a policy for while entered admin/controller/action/
in browser, directed to the admin panel, else if admin/
does not exist in URL, directed to the regular page.
For this goal, I've written some codes in _ViewStart.cshtml
but needs some 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 some codes for directing just to the /admin part
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
else
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
}