Joe Washek
Joe Washek

Reputation: 43

Get Web hostname in Startup

I've been searching for a way to get the hostname of the web application in the Startup class of my asp.net core 2.0 app. Specifically, in the Configure method I would like to dynamically set a service property based on the hostname.
For instance, I need to know if the host is running as http://servername/myapp or https://externalhost.com/myapp

Thank you for any help

Upvotes: 2

Views: 4518

Answers (2)

stefano portolano
stefano portolano

Reputation: 1

Try this:

 var host = app.Configuration.GetSection("APP_POOL_ID").Value.ToLower();

Upvotes: 0

Dag Baardsen
Dag Baardsen

Reputation: 922

You cannot distinguish between hostnames, but on Application Pool identities. Use this call to distinguish between identities:

System.Security.Principal.WindowsIdentity.GetCurrent().Name

Upvotes: 2

Related Questions