Reputation: 8637
This is related to my other question.
Most of scaffolding problem were resolved, but I'm getting error related to certificate:
In appsettings.json I have the following:
"Kestrel": {
"Endpoints": {
"Localhost": {
"Address": "127.0.0.1",
"Port": "53688"
},
"LocalhostHttps": {
"Address": "127.0.0.1",
"Port": "44384",
"Certificate": "HTTPS"
}
}
},
and in appsettings.Development.json:
"Certificates": {
"HTTPS": {
"Source": "Store",
"StoreLocation": "LocalMachine",
"StoreName": "My",
"Subject": "CN=localhost",
"AllowInvalid": true
},
And Environment is Development:
Why it's asking Certificate for Production?
And why I need Certificate for scaffolding?
Upvotes: 0
Views: 613
Reputation: 4177
If you dig around in the documentation a bit you'll see Kestrel does not support setting up an HTTPS endpoint via a configuration file. There is also a issue in Github asp.net/security that covers this in depth. You can set things up in the Program.cs file following this pattern....
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args)
{
IHostingEnvironment env = null;
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostingContext, config) =>
{
env = hostingContext.HostingEnvironment;
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
if (env.IsDevelopment())
{
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
if (appAssembly != null)
{
config.AddUserSecrets(appAssembly, optional: true);
}
}
config.AddEnvironmentVariables();
if (args != null)
{
config.AddCommandLine(args);
}
})
.UseKestrel(options =>
{
if (env.IsDevelopment())
{
options.Listen(IPAddress.Loopback, 44321, listenOptions =>
{
listenOptions.UseHttps("testcert.pfx", "ordinary");
});
}
else
{
options.Listen(IPAddress.Loopback, 5000);
}
})
.Build();
}
}
Upvotes: 1
Reputation: 11
This issue is documented by Microsoft/EF here.
The following is a direct copy and paste of their documentation (linked above).
ASP.NET Core 2.0 and Web Tools Known Issues
Certificate error when trying to apply EF migrations or using code generation
Issue:
When trying to apply EF migrations or when using code generation to scaffold code in an ASP.NET Core 2.0 application, you get error: 'No certificate named 'HTTPS' found in configuration for the current environment (Production).
Workaround:
Start a Developer Command Prompt, set the environment variable ASPNETCORE_ENVIRONMENT=Development and then start VS with this environment variable set
Also, I would not assume that you need to setup SSL for the purpose of scaffolding. I would disable SSL if you do not require it and try the workaround suggested by the linked documentation regardless of the current debug environment variables currently displayed in the project properties. Hopefully it helps.
Upvotes: 1