Reputation: 7049
I'm trying to get https working in ASP.NET Core 2.1 under VS2017 with IIS Express and the classic .NET framework (which I need for the classic Entity Framework).
With http, the app runs fine. Enabling https in the debug section of the project properties makes the new endpoint indeed appear in the IIS Express taskbar UI, but requesting it merely gets me "The connection was reset." rather than "localhost refused to connect."
Setting https in that pane modifies Properties\launchConfiguration.json", which in turn influences
.vs\config\applicationhost.config` on startup.
My web host is the classic default:
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
And I have nothing with regards to urls in my settings.json
.
(I don't think it's relevant because Kestrel is serving still in http even for https requests in this setup, correct?)
Upvotes: 2
Views: 1958
Reputation: 7239
It should work out of the box if you have the checkbox configure for HTTPS checked.
Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
Properties -> launchsettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64202",
"sslPort": 44395
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication4": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
That should be all you need. Create a new project if you can't get it to work and compare.
Upvotes: 2