Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get base url without accessing a request

How to get the base URL in AspNet core application without having a request?

I know from the Request you can get the scheme and host (ie $"{Request.Scheme}://{Request.Host}" would give something like https://localhost:5000), but is it possible to get this information from anywhere else?

In other words, if I have a service class that needs to build absolute URLs, how can I get the current URL when there is not an http request available?

UPDATE: Maybe that scenario does not even make sense since the hosting URL is totally external to the application and that's why it only makes sense to extract it from the Request host..

like image 499
diegosasw Avatar asked Oct 05 '16 02:10

diegosasw


1 Answers

i needed for some reason to get the base URL in Start.cs Configure, so i come up with this

var URLS = app.ServerFeatures.Get<IServerAddressesFeature>().Addresses;

like image 83
azaki Avatar answered Sep 22 '22 06:09

azaki