I know that I can use Url.Link()
to get URL of a specific route, but how can I get Web API base URL in Web API 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.
Pretty much all Web API 2 controllers inherit from ApiController but Controller is the base class in the new world. In MVC 6 the same Controller base class can be used whether you are writing a RESTful API or an MVC website.
In the action method of the request to the url "http://localhost:85458/api/ctrl/"
var baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority) ;
this will get you http://localhost:85458
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