Merge branch 'release/2.1' into dev

# Conflicts:
#	build/dependencies.props
This commit is contained in:
Chris Ross (ASP.NET) 2018-03-27 12:05:23 -07:00
commit b6b438f5fb
7 changed files with 48 additions and 2 deletions

View File

@ -5,6 +5,7 @@
<PropertyGroup Label="Package Versions">
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview3-17001</InternalAspNetCoreSdkPackageVersion>
<MicrosoftAspNetCoreDiagnosticsPackageVersion>2.1.0-preview3-32037</MicrosoftAspNetCoreDiagnosticsPackageVersion>
<MicrosoftAspNetCoreHostFilteringPackageVersion>2.1.0-preview3-32037</MicrosoftAspNetCoreHostFilteringPackageVersion>
<MicrosoftAspNetCoreHostingPackageVersion>2.1.0-preview3-32037</MicrosoftAspNetCoreHostingPackageVersion>
<MicrosoftAspNetCoreRoutingPackageVersion>2.1.0-preview3-32037</MicrosoftAspNetCoreRoutingPackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview3-32037</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>

View File

@ -1,4 +1,5 @@
{
"AllowedHosts": "example.com;localhost",
"Kestrel": {
"EndPoints": {
"Http": {

View File

@ -0,0 +1,21 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
namespace Microsoft.AspNetCore
{
internal class HostFilteringStartupFilter : IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{
return app =>
{
app.UseHostFiltering();
next(app);
};
}
}
}

View File

@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="$(MicrosoftAspNetCoreDiagnosticsPackageVersion)" PrivateAssets="None" />
<PackageReference Include="Microsoft.AspNetCore.HostFiltering" Version="$(MicrosoftAspNetCoreHostFilteringPackageVersion)" PrivateAssets="None" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(MicrosoftAspNetCoreHostingPackageVersion)" PrivateAssets="None" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="$(MicrosoftAspNetCoreRoutingPackageVersion)" PrivateAssets="None" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="$(MicrosoftAspNetCoreServerIISIntegrationPackageVersion)" PrivateAssets="None" />

View File

@ -182,6 +182,16 @@ namespace Microsoft.AspNetCore
logging.AddConsole();
logging.AddDebug();
})
.ConfigureServices((hostingContext, services) =>
{
var hosts = hostingContext.Configuration["AllowedHosts"]?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
services.AddHostFiltering(options =>
{
options.AllowedHosts = (hosts?.Length > 0 ? hosts : new[] { "*" });
});
services.AddTransient<IStartupFilter, HostFilteringStartupFilter>();
})
.UseIISIntegration()
.UseDefaultServiceProvider((context, options) =>
{

View File

@ -4,8 +4,11 @@
using System;
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HostFiltering;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace CreateDefaultBuilderOfTApp
{
@ -15,11 +18,12 @@ namespace CreateDefaultBuilderOfTApp
{
app.Run(context =>
{
return context.Response.WriteAsync(GetResponseMessage(webHostBuilderContext));
var message = GetResponseMessage(webHostBuilderContext, app.ApplicationServices.GetRequiredService<IOptions<HostFilteringOptions>>());
return context.Response.WriteAsync(message);
});
}
private static string GetResponseMessage(WebHostBuilderContext context)
private static string GetResponseMessage(WebHostBuilderContext context, IOptions<HostFilteringOptions> hostFilteringOptions)
{
// Verify ContentRootPath set
if (!string.Equals(Directory.GetCurrentDirectory(), context.HostingEnvironment.ContentRootPath, StringComparison.Ordinal))
@ -53,6 +57,13 @@ namespace CreateDefaultBuilderOfTApp
return $"Command line arguments not loaded into Configuration.";
}
// Verify allowed hosts were loaded
var hosts = string.Join(',', hostFilteringOptions.Value.AllowedHosts);
if (!string.Equals("example.com,localhost", hosts, StringComparison.Ordinal))
{
return $"AllowedHosts not loaded into Options.";
}
// TODO: Verify AddConsole called
// TODO: Verify AddDebug called
// TODO: Verify UseIISIntegration called

View File

@ -1,5 +1,6 @@
{
"settingsKey": "settingsValue",
"AllowedHosts": "example.com;localhost",
"Kestrel": {
"Endpoints": {
"HTTP": {