Add kestrel config to CreateDefaultBuilder

This commit is contained in:
Chris Ross (ASP.NET) 2017-12-21 14:02:47 -08:00
parent ee9b080875
commit 7511a4da7f
4 changed files with 35 additions and 38 deletions

View File

@ -2,61 +2,47 @@
"Kestrel": { "Kestrel": {
"EndPoints": { "EndPoints": {
"Http": { "Http": {
"Address": "127.0.0.1", "Url": "http://localhost:5005"
"Port": 5000 }
},
// To enable HTTPS using a certificate file, set the path to a .pfx file in // To enable HTTPS using a certificate file, set the path to a .pfx file in
// the "Path" property below and configure the password in user secrets. // the "Path" property below and configure the password in user secrets.
// The "Password" property should be set in user secrets. // The "Password" property should be set in user secrets.
//"HttpsInlineCertFile": { //"HttpsInlineCertFile": {
// "Address": "127.0.0.1", // "Url": "http://localhost:5005"
// "Port": 5001,
// "Certificate": { // "Certificate": {
// "Source": "File", // "Path": "<path to .pfx file>",
// "Path": "<path to .pfx file>" // "Password: "<cert password>"
// } // }
//}, //},
//"HttpsInlineCertStore": { //"HttpsInlineCertStore": {
// "Address": "127.0.0.1", // "Url": "http://localhost:5005"
// "Port": 5002,
// "Certificate": { // "Certificate": {
// "Source": "Store",
// "Subject": "", // "Subject": "",
// "StoreName": "", // "Store": "",
// "StoreLocation": "", // "Location": "",
// "AllowInvalid": "" // Set to "true" to allow invalid certificates (e.g. expired) // "AllowInvalid": "" // Set to "true" to allow invalid certificates (e.g. expired)
// } // }
//}, //},
// To enable this endpoint, set the path to a .pfx file in the "Path" property // This uses the cert defined under Certificates/Default or the development cert.
// of the "TestCert" certificate defined under the "Certificates" section. //"HttpsDefaultCert": {
// Configure the password in user secrets. // "Url": "http://localhost:5005"
//"HttpsCertFile": {
// "Address": "127.0.0.1",
// "Port": 5003,
// "Certificate": "TestCert"
//} //}
//"HttpsCertStore": {
// "Address": "127.0.0.1",
// "Port": 5004,
// "Certificate": "TestCertInStore"
//},
} }
}, },
"Certificates": { "Certificates": {
//"TestCert": { //"Default": {
// "Source": "File", // "Path": "<file>",
// "Path": "" // "Password": "<password>"
//}, //},
//"TestCertInStore": { // From cert store:
// "Source": "Store", //"Default": {
// "Subject": "", // "Subject": "",
// "StoreName": "", // "Store": "",
// "StoreLocation": "", // "Location": "",
// "AllowInvalid": "" // Set to "true" to allow invalid certificates (e.g. expired certificates) // "AllowInvalid": "" // Set to "true" to allow invalid certificates (e.g. expired certificates)
//} //}
} }

View File

@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The following defaults are applied to the returned <see cref="WebHostBuilder"/>: /// The following defaults are applied to the returned <see cref="WebHostBuilder"/>:
/// use Kestrel as the web server, /// use Kestrel as the web server and configure it using the application's configuration providers,
/// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>, /// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>,
/// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json', /// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json',
/// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly, /// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly,
@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The following defaults are applied to the returned <see cref="WebHostBuilder"/>: /// The following defaults are applied to the returned <see cref="WebHostBuilder"/>:
/// use Kestrel as the web server, /// use Kestrel as the web server and configure it using the application's configuration providers,
/// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>, /// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>,
/// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json', /// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json',
/// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly, /// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly,
@ -148,7 +148,10 @@ namespace Microsoft.AspNetCore
public static IWebHostBuilder CreateDefaultBuilder(string[] args) public static IWebHostBuilder CreateDefaultBuilder(string[] args)
{ {
var builder = new WebHostBuilder() var builder = new WebHostBuilder()
.UseKestrel() .UseKestrel((builderContext, options) =>
{
options.Configure(builderContext.Configuration.GetSection("Kestrel"));
})
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) => .ConfigureAppConfiguration((hostingContext, config) =>
{ {
@ -198,7 +201,7 @@ namespace Microsoft.AspNetCore
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The following defaults are applied to the returned <see cref="WebHostBuilder"/>: /// The following defaults are applied to the returned <see cref="WebHostBuilder"/>:
/// use Kestrel as the web server, /// use Kestrel as the web server and configure it using the application's configuration providers,
/// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>, /// set the <see cref="IHostingEnvironment.ContentRootPath"/> to the result of <see cref="Directory.GetCurrentDirectory()"/>,
/// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json', /// load <see cref="IConfiguration"/> from 'appsettings.json' and 'appsettings.[<see cref="IHostingEnvironment.EnvironmentName"/>].json',
/// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly, /// load <see cref="IConfiguration"/> from User Secrets when <see cref="IHostingEnvironment.EnvironmentName"/> is 'Development' using the entry assembly,

View File

@ -61,7 +61,8 @@ namespace Microsoft.AspNetCore.Tests
{ {
// Assert server is Kestrel // Assert server is Kestrel
Assert.Equal("Kestrel", response.Headers.Server.ToString()); Assert.Equal("Kestrel", response.Headers.Server.ToString());
// Set from default config
Assert.Equal("http://localhost:5002/", deploymentResult.ApplicationBaseUri);
// The application name will be sent in response when all asserts succeed in the test app. // The application name will be sent in response when all asserts succeed in the test app.
Assert.Equal(applicationName, responseText); Assert.Equal(applicationName, responseText);
} }

View File

@ -1,3 +1,10 @@
{ {
"settingsKey": "settingsValue" "settingsKey": "settingsValue",
"Kestrel": {
"Endpoints": {
"HTTP": {
"Url": "http://localhost:5002"
}
}
}
} }