1

I have a .net core API that runs fine under http but when I check to enable SSL it won't even load program or startup.cs.

I suspect some sort of IIS Express or Binding issue but I don't see anything wrong.

LaunchSettings:

{
  "iisSettings": {
  "windowsAuthentication": false,
  "anonymousAuthentication": true,
  "iisExpress": {
  "applicationUrl": "http://localhost:5001/",
  "sslPort": 45150
}
},
  "profiles": {
     "IIS Express": {
     "commandName": "IISExpress",
     "launchBrowser": true,
     "environmentVariables": {
     "ASPNETCORE_ENVIRONMENT": "Development"
    }
},
"Bullies.API": {
  "commandName": "Project",
  "launchBrowser": true,
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  },
  "applicationUrl": "https://localhost:45150;http://localhost:5001"
    }
  }
}

I've restarted VS 2019 several times and I am running in Admin mode.

I've cleaned out all certs with:

dotnet dev-certs https --clean

And recreated with

dotnet dev-certs https --trust

In the browser I get no error messages that mean anything to me just ERR_CONNECTION_RESET and this header.

Request URL: https://localhost:45150/
Referrer Policy: strict-origin-when-cross-origin

Provisional headers are shown
  sec-ch-ua: "Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"
  sec-ch-ua-mobile: ?0
  sec-ch-ua-platform: "Windows"
  Upgrade-Insecure-Requests: 1
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

What am I missing?

Edit

Added program.cs:

public class Program
{
    public static void Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
        .Enrich.FromLogContext()
        .WriteTo.Console()
        .CreateLogger();

        try
        {
            Log.Information("Starting up");
            CreateHostBuilder(args).Build().Run();
        }
        catch (Exception ex)
        {
            Log.Fatal(ex, "Application start-up failed");
        }
        finally
        {
            Log.CloseAndFlush();
        }            
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .UseSerilog()
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
            .ConfigureServices((hostContext, services) =>
            {
                services.AddHostedService<Stuff>();
            });
}

Solved

This is what finally did it. Recreating the IIS Express Certs:

https://improveandrepeat.com/2020/05/recreate-the-self-signed-https-certificate-for-localhost-in-iis-express/

halfer
  • 19,824
  • 17
  • 99
  • 186
GPGVM
  • 5,515
  • 10
  • 56
  • 97
  • 1
    What's your Program.cs file look like? – GH DevOps Nov 08 '21 at 17:02
  • @GHDevOps Added program.cs – GPGVM Nov 08 '21 at 17:23
  • 1
    Inside Startup.cs are you using the Https redirect middleware? (app.UseHttpsRedirection();) – GH DevOps Nov 08 '21 at 17:37
  • 1
    ^ And check if you have IIS Rewrite module active in IIS. Have you created an https binding in IIS? – LinkedListT Nov 08 '21 at 18:02
  • @GHDevOps yes in my startup: app.UseHttpsRedirection(); – GPGVM Nov 08 '21 at 18:51
  • @LinkedListT Running IIS express local dev so there is no rewrite that I know of? The binding question though is a good one. I thought using the app.UseHttpsRedirect middleware did the binding but your suggesting it's a seperate step? – GPGVM Nov 08 '21 at 18:53
  • 1
    Ah, if you're using IIS Express I don't think it's relevant. Try forcing a new port and SSL cert https://stackoverflow.com/a/57706281/9936356 – LinkedListT Nov 08 '21 at 19:03
  • 1
    I'm guessing it's the cert. Do you have Fiddler or Wireshark? Capture the traffic and see if that gives you more info than your browser – GH DevOps Nov 08 '21 at 21:05

0 Answers0