0

When I try to run nopCommerce 4.0 locally in VisualStudio with SSL, I get the error ERR_EMPTY_RESPONSE. Running without HTTPS works fine. I am testing integration with an external login and I need to run HTTPS locally to avoid mixed content problems.

I know there are several SO posts about this, but they all lead me to the same place. My latest attempt is based on this article.

In my Startup.cs, I have:

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    services.AddMvc(
        options =>
        {
            options.SslPort = 55391;
            options.Filters.Add(new RequireHttpsAttribute());
        }
    );
    services.AddAntiforgery(
        options =>
        {
            options.Cookie.Name = "_af";
            options.Cookie.HttpOnly = true;
            options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
            options.HeaderName = "X-XSRF-TOKEN";
        }
    );
    return services.ConfigureApplicationServices(Configuration);
}

In certificate.json, I have:

{
    "certificateSettings": {
        "filename": "localhost.pfx",
        "password": "secretpassword"
    }  
}

In Program.cs, I have:

public static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddEnvironmentVariables()
    .AddJsonFile("certificate.json", optional: true, reloadOnChange: true)
    .AddJsonFile($"certificate.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true, reloadOnChange: true)
    .Build();

    var certificateSettings = config.GetSection("certificateSettings");
    string certificateFileName = certificateSettings.GetValue<string>("filename");
    string certificatePassword = certificateSettings.GetValue<string>("password");

    var certificate = new X509Certificate2(certificateFileName, certificatePassword);

    var host = WebHost.CreateDefaultBuilder(args)
        .UseKestrel(options =>
        {
            options.AddServerHeader = false;
            options.Listen(IPAddress.Loopback, 55391, listenOptions =>
            {
                listenOptions.UseHttps(certificate);
            });
            options.Listen(IPAddress.Loopback, 55390);
        })
        .UseStartup<Startup>()
        .CaptureStartupErrors(true)
        .Build();

    host.Run();
}

I have ASPNETCORE_HTTPS_PORT set to 55391 in my Nop.Web project settings.

When I run this, I get the error ERR_EMPTY_RESPONSE.

If I remove all of the HTTPS options and just go with the standard setup, everything works fine.

Edit: I have to run this project with the Nop.Web profile, so I can't run it with IIS Express and just get the SSL settings in the project properties.

Edit #2: I noticed that when I get this error, the browser is being redirected from https://localhost:55391 to http://localhost:55391 (no s). I'm not sure why.

mrcoulson
  • 1,331
  • 6
  • 20
  • 35
  • Sorry. I should have mentioned that. I have to run the project with the Nop.Web profile instead of IIS Express, so that option isn't available in the project settings. – mrcoulson Oct 16 '18 at 17:01
  • Is SSL setting set to true in database table (I am not sure of table name but it might be [Store])? – Sushil Jadhav Oct 26 '18 at 09:29
  • When I add these, I am redirected from the https port back to http. So, if I ask for https://localhost:55391, I am sent to http://localhost:55390. – mrcoulson Oct 30 '18 at 20:11

0 Answers0