1: How does the front end obtain the controller routing name:
{
string route = "";
if (this.Url.RequestContext.RouteData.Values.Count > 0)
{
route = this.Url.RequestContext.RouteData.Values["controller"].ToString();
}
}
2: How to get the route name in the back-end controller:
Customize a filter to inherit ActionFilterAttribute
public class ActionFilter : ActionFilterAttribute
{
//Rewrite the OnActionExecuting method
public override void OnActionExecuting(ActionExecutingContext context)
{
string controllerName = context.RouteData.Values["controller"].ToString();
string actionName = context.RouteData.Values["action"].ToString();
}
}