Search code examples
c#asp.net-coreaspnetboilerplate

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


Solution

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

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