What's the correct way to get the full url (including protocol and domain) for a controller and action? I need this to be able to send links to pages via email.
I was hoping to just use Url.Action() and concatenate it onto the current server hostname from Request.Url. However, it seems that Url.Action is context sensitive and so will not show the full path if you are already within the same controller.
Any ideas?
Thanks
James
By specifying the protocol and host, the result is now "https://your-website/Home/Privacy" . However, if you omit the host parameter but keep the protocol parameter, the result will still be an absolute URL, because the host parameter will default to the host used for the current HTTP request.
The Controller in MVC architecture handles any incoming URL request. The Controller is a class, derived from the base class System. Web. Mvc.
Action method only creates the url not the complete hyperlink, to create hyperlink we need to use Html. ActionLink covered next. To access these querystring values in the action method, we can use Request.QueryString like below. CONTROLLER ACTION METHOD public ActionResult Index() { string com = Request.
There are overloads of Url.Action() that take the hostname, protocol, etc. Calling one of these overloads will generate a fully-qualified URL suitable for emailing.
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