Skip to content

Web Templates #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dansiegel opened this issue May 15, 2017 · 11 comments
Closed

Web Templates #797

dansiegel opened this issue May 15, 2017 · 11 comments

Comments

@dansiegel
Copy link
Contributor

The new templates have quite a bit more going on than templates in the past, which is a good thing. However, if I create a new project like dotnet new webapi -au Individual the current result is a little less than desirable.

If I do dotnet run I get the following error

Dans-MacBook-Air:Demo.Api dansiegel$ dotnet run

Unhandled Exception: System.InvalidOperationException: Unable to configure HTTPS endpoint. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054. ---> System.Collections.Generic.KeyNotFoundException: No certificate named 'HTTPS' found in configuration for the current environment (Production).
   at Microsoft.AspNetCore.CertificateLoader.LoadSingle(String certificateName)
   at Microsoft.AspNetCore.CertificateLoader.Load(IConfigurationSection certificateConfiguration)
   at Microsoft.AspNetCore.KestrelServerOptionsSetup.<>c__DisplayClass6_0.<BindEndPoint>b__0(ListenOptions listenOptions)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.KestrelServerOptionsSetup.<>c__DisplayClass6_0.<BindEndPoint>b__0(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions.Listen(IPEndPoint endPoint, Action`1 configure)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions.Listen(IPAddress address, Int32 port, Action`1 configure)
   at Microsoft.AspNetCore.KestrelServerOptionsSetup.BindEndPoint(KestrelServerOptions options, IConfigurationSection endPoint, CertificateLoader certificateLoader)
   at Microsoft.AspNetCore.KestrelServerOptionsSetup.BindConfiguration(KestrelServerOptions options)
   at Microsoft.AspNetCore.KestrelServerOptionsSetup.Configure(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.Extensions.Options.OptionsManager`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.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass17_0.<RealizeService>b__0(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   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 Demo.Api.Program.BuildWebHost(String[] args)
   at Demo.Api.Program.Main(String[] args)

If I try to deploy to an Azure Web App I get the following error:

HTTP Error 502.5 - Process Failure


Common causes of this issue:

The application process failed to start
The application process started but then stopped
The application process started but failed to listen on the configured port

Troubleshooting steps:

Check the system event log for error messages
Enable logging the application process’ stdout messages
Attach a debugger to the application process and inspect

For more information visit: http://go.microsoft.com/fwlink/?LinkID=808681

The templates really could use some sort of ReadMe added to them to help developers get started. For instance if I'm on a Mac what do I need to do to setup my local environment for testing. If I'm on my PC same thing... if I'm deploying to Linux, IIS, Azure...

Another thing would be following @RehanSaeed's example and provide some action items of any tweaks or things that a developer should do next.

@sayedihashimi
Copy link
Member

Do you have the ASPNETCORE_ENVIRONMENT set to Development? That should help.

cc @danroth27

@dansiegel
Copy link
Contributor Author

That was the result with ASPNETCORE_ENVIRONMENT set to Development

@danroth27
Copy link
Member

Yup, this is a big gap in Preview 1 that we don't have an easy way to setup a development certificate for HTTPS on non Windows platforms. You have to setup one manually using openssl (see https://go.microsoft.com/fwlink/?linkid=848054).

For Preview 2 we plan to provide tooling that you run once to setup a development certificate for local HTTPS development.

@dansiegel
Copy link
Contributor Author

If the local environment will be taken care of in Preview 2 that will be helpful. But still would be good to provide some documentation / checklist for here's what you need to do before deploying to a remote server like Azure/IIS/Linux

@danroth27
Copy link
Member

Yup, will do: dotnet/AspNetCore.Docs#3367

@RehanSaeed
Copy link

Why not include the pfx certificate in the template instead of creating one. It's self signed certificate so it will show red a security warning but that's totally expected. If the worry is that many people will have trusted the certificate, it should still show red in the browser address bar.

@danroth27
Copy link
Member

@RehanSaeed We've been trying really hard to avoid putting certificates in the project because we think it's an anti-pattern. In general, certificates should be carefully protected and not put in source control.

@dansiegel
Copy link
Contributor Author

@danroth27 couldn't agree more that putting certificates in source control is generally a bad thing. That said the issue I wanted to highlight was that we currently have a poor developer experience.

From the perspective of being able to go from File -> New or in this case dotnet new, to having something running it wouldn't be a horrible thing imho to have a self signed cert included until the tooling can generate one locally on the developer's machine. Besides that when you're going to https://localhost it doesn't really matter where the cert comes from it'll be untrusted.

@danroth27
Copy link
Member

Instead of using a .pfx in the project we will be improving the experience in preview2 by providing xplat tooling for generating a development HTTPS certificate into the current user store.

@dansiegel
Copy link
Contributor Author

@danroth27 I would hope that the tooling provided would work for generating a temporary certificate for a UWP template as well.

@mlorbetske
Copy link
Contributor

Closing this as the UWP concerns are discussed in #770 and the item tracking the certificate generation utility is here aspnet/DotNetTools#296. The approach seems to have changed a bit to now be an MSBuild task (source here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants