I. Getting URLs is simple. ASP. NET is common:
[1] obtain the complete url (Protocol name + domain name + virtual directory name + file name + parameter)
String url = Request. Url. ToString ();
[2] obtain the virtual directory name + page name + parameter:
String url = Request. RawUrl;
(Or string url = Request. Url. PathAndQuery ;)
[3] obtain the virtual directory name + Page name:
String url = HttpContext. Current. Request. Url. AbsolutePath;
(Or string url = HttpContext. Current. Request. Path ;)
[4] retrieve domain names:
String url = HttpContext. Current. Request. Url. Host;
[5] get parameters:
String url = HttpContext. Current. Request. Url. Query;
[6] obtain the port:
Request. Url. Port
2. Obtain the current controller and action
RouteData. Route. GetRouteData (this. HttpContext). Values ["controller"]
RouteData. Route. GetRouteData (this. HttpContext). Values ["action"]
Or
RouteData. Values ["controller"]
RouteData. Values ["action"]
If you can use
ViewContext. RouteData. Route. GetRouteData (this. Context). Values ["controller"]
ViewContext. RouteData. Route. GetRouteData (this. Context). Values ["action"]
Or
ViewContext. RouteData. Values ["controller"]
ViewContext. RouteData. Values ["action"]