Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the best way to get the base URL from a controller

Tags:

asp.net-mvc

Inside my controller how would i get the base URL.

for example, if my url is:

http://www.mysite.com/MyController/MyAction

I want to have a function that returns :

http://www.mysite.com
like image 668
leora Avatar asked Dec 26 '11 20:12

leora


People also ask

How do I find the base URL of a controller?

How to Get the Base URL in an MVC Controller. Here's a simple one-liner to get the job done. var baseUrl = string. Format(“{0}://{1}{2}”, Request.

How do you give a controller a URL?

UrlHelper u = new UrlHelper(this. ControllerContext. RequestContext); string url = u. Action("About", "Home", null);

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.


1 Answers

I use:

Request.Url.GetLeftPart(UriPartial.Authority);
like image 174
santiagoIT Avatar answered Sep 28 '22 03:09

santiagoIT