0

Is there a way to compile / build our application once, but be able to deploy to either IIS (using the in-process hosting model) or run standalone using Kestrel?

This is an application that may be in some cases cloud hosted (Azure) but also packaged and installed standalone essentially a desktop-based application service web pages in an intranet scenario.

Currently the certificate file and password are loaded in the IWebHostBuilder implementation:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .ConfigureServices(services =>
            {
                services.AddSingleton<ConfigurationContainer>(ConfigurationContainer);
            })                
            .UseKestrel(options =>
            {
                options.ConfigureEndpointDefaults(listenOptions =>
                {                        
                    if (_useHttps)                        
                        listenOptions.UseHttps(_certificateFile, _certificatePword);                        
                });
            })
            .UseUrls("xxxxx")
            .UseStartup<Startup>();

The objective is as above - to be able to essentially host the same build in IIS using (in-process hosting) or run up standalone using Kestrel.

James Harcourt
  • 6,017
  • 4
  • 22
  • 42

1 Answers1

1

In theory, the dlls work identically in both. Because you've chosen to configure the Kestrel options in C#, you're likely hitting interesting scenarios in IIS. Try configuring Kestrel and the URLs in appsettings.json:

"Kestrel": {
  "EndPoints": {
  "Http": {
  "Url": "http://localhost:5555"
 }}}

Then in IIS, use IIS to configure these details.

See also https://stackoverflow.com/a/52077756/702931

robrich
  • 13,017
  • 7
  • 36
  • 63