Make UseIISIntegration idempotent (#274)
This commit is contained in:
parent
359faf7e51
commit
e4cf12017b
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.IISIntegration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||
|
||||
[assembly: AssemblyMetadata("Serviceable", "True")]
|
||||
[assembly: NeutralResourcesLanguage("en-us")]
|
||||
|
|
|
|||
|
|
@ -30,12 +30,21 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
throw new ArgumentNullException(nameof(hostBuilder));
|
||||
}
|
||||
|
||||
// Check if `UseIISIntegration` was called already
|
||||
if (hostBuilder.GetSetting(nameof(UseIISIntegration)) != null)
|
||||
{
|
||||
return hostBuilder;
|
||||
}
|
||||
|
||||
var port = hostBuilder.GetSetting(ServerPort) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPort}");
|
||||
var path = hostBuilder.GetSetting(ServerPath) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPath}");
|
||||
var pairingToken = hostBuilder.GetSetting(PairingToken) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{PairingToken}");
|
||||
|
||||
if (!string.IsNullOrEmpty(port) && !string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(pairingToken))
|
||||
{
|
||||
// Set flag to prevent double service configuration
|
||||
hostBuilder.UseSetting(nameof(UseIISIntegration), true.ToString());
|
||||
|
||||
var address = "http://localhost:" + port;
|
||||
hostBuilder.CaptureStartupErrors(true);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
// 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.Linq;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||
{
|
||||
public class IISExtensionTests
|
||||
{
|
||||
[Fact]
|
||||
public void CallingUseIISIntegrationMultipleTimesWorks()
|
||||
{
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.UseIISIntegration()
|
||||
.Configure(app => { });
|
||||
var server = new TestServer(builder);
|
||||
|
||||
var filters = server.Host.Services.GetServices<IStartupFilter>()
|
||||
.OfType<IISSetupFilter>();
|
||||
|
||||
Assert.Equal(1, filters.Count());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
"version": "1.1.0-*",
|
||||
"buildOptions": {
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
},
|
||||
"dependencies": {
|
||||
"dotnet-test-xunit": "2.2.0-*",
|
||||
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0-*",
|
||||
|
|
|
|||
Loading…
Reference in New Issue