I would like to provide some URL separation for my public / anonymous controllers and views from controllers and admin / authenticated views. Therefore, I made full use of Attribute Routing to have more control over my URLs. I wanted my public urls to start with "~ / admin / etc." while my public urls would not have such a prefix.
Open controller (one of several)
[RoutePrefix("Home")]
public class HomeController : Controller
{
[Route("Index")]
public ActionResult Index()
{
}
Admin Controller (one of several)
[RoutePrefix("Admin/People")]
public class PeopleController : Controller
{
[Route("Index")]
public ActionResult Index()
{
}
This allows me to have public URLs like:
http:
... and admin / authenticated URL, for example:
http://myapp/admin/people/someaction
, , "" "" . , ?
, -
if (Request.Url.LocalPath.StartsWith("/Admin"))
... "". ,
HttpContext.Current.Request.RequestContext.RouteData.Values
... "admin" , , .
, , , "admin" ?