在 Startup 中获取 Web 主机名
Get Web hostname in Startup
我一直在寻找一种方法来在我的 asp.net 核心 2.0 应用程序的启动 class 中获取 Web 应用程序的主机名。具体来说,在 Configure 方法中,我想根据主机名动态设置服务 属性。
例如,我需要知道主机是否 运行 为 http://servername/myapp or https://externalhost.com/myapp
感谢您的帮助
您无法区分主机名,但可以区分应用程序池标识。
使用此调用来区分身份:
System.Security.Principal.WindowsIdentity.GetCurrent().Name
我一直在寻找一种方法来在我的 asp.net 核心 2.0 应用程序的启动 class 中获取 Web 应用程序的主机名。具体来说,在 Configure 方法中,我想根据主机名动态设置服务 属性。
例如,我需要知道主机是否 运行 为 http://servername/myapp or https://externalhost.com/myapp
感谢您的帮助
您无法区分主机名,但可以区分应用程序池标识。 使用此调用来区分身份:
System.Security.Principal.WindowsIdentity.GetCurrent().Name