What is the best way to get the base url from the controller

Inside my controller, how would I get the base URL.

for example if my url:

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

I want to get the returned function:

 http://www.mysite.com 
+5
source share
2 answers

I use:

 Request.Url.GetLeftPart(UriPartial.Authority); 
+15
source

This is the method that I use in my C # application

  public static string base_url() { return string.Format("{0}://{1}/", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority); } 

Note that this returns the port also if your development server uses a different port than 80

0
source

Source: https://habr.com/ru/post/971802/


All Articles