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

Commit a95dcd2

Browse files
committed
Add an UseHttps overload for the default https provider
1 parent a4d2b8d commit a95dcd2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

samples/SampleApp/Startup.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,17 @@ public static Task Main(string[] args)
104104

105105
options.ListenLocalhost(basePort + 2, listenOptions =>
106106
{
107-
listenOptions.UseHttps(StoreName.My, "aspnet.test", StoreLocation.CurrentUser);
107+
// Use default dev cert
108+
listenOptions.UseHttps();
108109
});
109110

110111
options.ListenAnyIP(basePort + 3);
111112

113+
options.ListenAnyIP(basePort + 4, listenOptions =>
114+
{
115+
listenOptions.UseHttps(StoreName.My, "aspnet.test", StoreLocation.CurrentUser);
116+
});
117+
112118
options.UseSystemd();
113119

114120
// The following section should be used to demo sockets

src/Kestrel.Https/ListenOptionsHttpsExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Security.Cryptography.X509Certificates;
77
using Microsoft.AspNetCore.Server.Kestrel.Core;
8+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
89
using Microsoft.AspNetCore.Server.Kestrel.Https;
910
using Microsoft.AspNetCore.Server.Kestrel.Https.Internal;
1011
using Microsoft.Extensions.DependencyInjection;
@@ -17,6 +18,18 @@ namespace Microsoft.AspNetCore.Hosting
1718
/// </summary>
1819
public static class ListenOptionsHttpsExtensions
1920
{
21+
/// <summary>
22+
/// Configure Kestrel to use HTTPS with the default development certificate.
23+
/// </summary>
24+
/// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param>
25+
/// <returns>The <see cref="ListenOptions"/>.</returns>
26+
public static ListenOptions UseHttps(this ListenOptions listenOptions)
27+
{
28+
var httpsProvider = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService<IDefaultHttpsProvider>();
29+
httpsProvider.ConfigureHttps(listenOptions);
30+
return listenOptions;
31+
}
32+
2033
/// <summary>
2134
/// Configure Kestrel to use HTTPS.
2235
/// </summary>

0 commit comments

Comments
 (0)