-
Notifications
You must be signed in to change notification settings - Fork 524
Determining Hosting Environment While Configuring Kestrel and UseHttps #1334
Comments
It was just answered on another thread that I just saw: dotnet/aspnetcore#1915 (comment) ... and if you don't use command-line config, env var config, a config file, etc., then you can read the |
It turns out you can use
It really feels like this should be easier. |
Assigning to @CesarBS for investigation |
@RehanSaeed How can you handle the .UseUrls() to wrap an if statment around it?
|
@dotnetshadow Couldn't you do something like:
You can get |
@RehanSaeed that's pretty cool, but what happens if you publish to an IIS environment? |
@dotnetshadow Well, that would be a Production environment, so in my example above it would use the https URL. |
@RehanSaeed thanks for that, I wasn't sure if IIS would still be able to use the .UseUrls() for a live site like foo.com
|
IIS overwrites UseUrls. |
@Tratcher ahh thank you I didn't know that. What about options.UseHttps() does that get overridden? |
It will (though that may be broken right now in dev). @JunTaoLuo Do you have UseIISIntegration setting the new PreferHostingUrls? |
@davidfowl has some ideas for another (nicer) workaround. |
@Tratcher UseIISIntegration will set PreferHostingUrls after we address aspnet/IISIntegration#352 |
@Tratcher ahh thank you didn't know there was PreferHostingUrls thing any documentation on that? |
@dotnetshadow it's new for 2.0: |
This covers #1713 too. |
Is is possible to set UseHttps from Startup class? |
Yes:
|
@RehanSaeed I was able to find a slightly shorter way before this gets implemented properly:
|
Another way to do this:
|
In the ASP.NET Core Main method below, how can I determine the hosting environment, so I can switch between different certificate files for HTTPS?
The text was updated successfully, but these errors were encountered: