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
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.
UrlHelper u = new UrlHelper(this. ControllerContext. RequestContext); string url = u. Action("About", "Home", null);
The Controller in MVC architecture handles any incoming URL request. The Controller is a class, derived from the base class System. Web. Mvc.
I use:
Request.Url.GetLeftPart(UriPartial.Authority);
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