1, http://www.php.cn/code/6617.html "target=" _blank "> View
String controller = ViewContext.RouteData.Route.GetRouteData (this. Context). values["Controller"]. ToString (); String controller = viewcontext.routedata.values["Controller"]. ToString ();
2. In the action of the Controller
String controller = RouteData.Route.GetRouteData (this. HttpContext). values["Controller"]. ToString (); String controller = routedata.values["Controller"]. ToString ();
3, the filter
For example, in ActionFilterAttribute, this is usually the time to implement an inheritance class, and then rewrite the related methods.
In the overridden method, if the name of the controller is required.
<summary>///Authentication permission to check if the user is logged in (the action will be performed before execution)//</summary>///<param name= "Filtercontext" > </param>public override void OnActionExecuting (ActionExecutingContext filtercontext) {base. OnActionExecuting (Filtercontext); String controller = filtercontext.routedata.values["Controller"]. ToString (); controller = controller + "Controller";}
4. In Public methods
<summary>///gets the controller full name of the current page///</summary>///<returns></returns>public string Getcurrentcontroller () {String controller = httpcontext.current.request.requestcontext.routedata.values[" Controller "]. ToString (); if (!string. Isnullorwhitespace (Controller) {controller = controller + "Controller";} Else{controller = "";} return controller;}
The above is the content of the method of obtaining the controller name in ASP. Topic.alibabacloud.com (www.php.cn) for more information!