Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Provide a nice error message when the HTTPS certificate is not configured for the current environment #83

Closed
@danroth27

Description

@danroth27

Currently if you have a kestrel endpoint configured with a named certificate that isn't configured for the current environment you get an exception telling you that the certificate is missing. We should handle this exception and provide a reasonable error message to the user.

Current behavior:

~\Desktop\templates2\mvc-individual> $env:ASPNETCORE_ENVIRONMENT=""
~\Desktop\templates2\mvc-individual> dotnet run

Unhandled Exception: System.InvalidOperationException: No certificate named HTTPS found in configuration
   at Microsoft.AspNetCore.KestrelServerOptionsSetup.<>c__DisplayClass4_0.<BindEndPoint>b__0(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions.Listen(IPEndPoint endPoint, Action`1 configure)
   at Microsoft.AspNetCore.KestrelServerOptionsSetup.BindEndPoint(KestrelServerOptions options, IConfigurationSection endPoint, Dictionary`2 certificates)
   at Microsoft.AspNetCore.KestrelServerOptionsSetup.BindConfiguration(KestrelServerOptions options)
   at Microsoft.Extensions.Options.LegacyOptionsCache`1.CreateOptions()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
   at Microsoft.Extensions.Options.LegacyOptionsCache`1.get_Value()
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.CreateServiceContext(IOptions`1 options, ILoggerFactory loggerFactory)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer..ctor(IOptions`1 options, ITransportFactory transportFactory, ILoggerFactory loggerFactory)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureServer()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at mvc_individual.Program.BuildWebHost(String[] args)
   at mvc_individual.Program.Main(String[] args)

Proposed behavior:

~\Desktop\templates2\mvc-individual> $env:ASPNETCORE_ENVIRONMENT=""
~\Desktop\templates2\mvc-individual> dotnet run

No certificate named HTTPS found in configuration for the current environment (Production). For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions