Can someone tell me how I can get the URL that was used to call my route when I am in the controller? It seems simple but I can't find any reference on how to do it. If u need an example I can explain more .. Previously I asked a route question and someone told me how I could check which route was met. This time my needs are a bit different.
Thanks,
Mandy
Use the Url property of the Request object.
public ActionResult MyAction()
{
var url = Request.Url;
/// .....
return View();
}
That will return a Uri object with everything you need.
You might also be interested in the controller's RouteData property, which provides more detailed information about the parsed route.
Since you have a reference to the Request property of Controller, you can just do:
var url = Request.Url.ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With