Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the fully qualified url for a controller and action?

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

like image 848
James Avatar asked Feb 19 '09 22:02

James


People also ask

How do I get the absolute URL in .NET core?

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.

What is controller in URL?

The Controller in MVC architecture handles any incoming URL request. The Controller is a class, derived from the base class System. Web. Mvc.

What is action method in URL?

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.


1 Answers

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.

like image 99
Levi Avatar answered Oct 12 '22 21:10

Levi