[IIS] Move to GenericHost (#24280)
This commit is contained in:
parent
0437117cfb
commit
085921305a
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
|
@ -12,6 +13,7 @@ using Microsoft.AspNetCore.Http;
|
|||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Server.IIS;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace NativeIISSample
|
||||
{
|
||||
|
|
@ -115,16 +117,20 @@ namespace NativeIISSample
|
|||
"WEBSOCKET_VERSION"
|
||||
};
|
||||
|
||||
public static void Main(string[] args)
|
||||
public static Task Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseIIS()
|
||||
.UseIISIntegration()
|
||||
.UseStartup<Startup>()
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseIIS()
|
||||
.UseIISIntegration()
|
||||
.UseStartup<Startup>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
return host.RunAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
|
||||
{
|
||||
public class TestServer: IDisposable, IStartup
|
||||
public class TestServer : IDisposable
|
||||
{
|
||||
private const string InProcessHandlerDll = "aspnetcorev2_inprocess.dll";
|
||||
private const string AspNetCoreModuleDll = "aspnetcorev2.dll";
|
||||
|
|
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
|
|||
public TestConnection CreateConnection() => new TestConnection(_currentPort);
|
||||
|
||||
private static IISServerOptions _options;
|
||||
private IWebHost _host;
|
||||
private IHost _host;
|
||||
|
||||
private string _appHostConfigPath;
|
||||
private int _currentPort;
|
||||
|
|
@ -131,16 +131,24 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
|
|||
|
||||
private int Main(IntPtr argc, IntPtr argv)
|
||||
{
|
||||
var builder = new WebHostBuilder()
|
||||
.UseIIS()
|
||||
.ConfigureServices(services =>
|
||||
_host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = _options.MaxRequestBodySize);
|
||||
services.AddSingleton<IStartup>(this);
|
||||
services.AddSingleton(_loggerFactory);
|
||||
webHostBuilder
|
||||
.UseIIS()
|
||||
.UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName)
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Map("/start", builder => builder.Run(context => context.Response.WriteAsync("Done")));
|
||||
_appBuilder(app);
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = _options.MaxRequestBodySize);
|
||||
services.AddSingleton(_loggerFactory);
|
||||
});
|
||||
})
|
||||
.UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName);
|
||||
_host = builder.Build();
|
||||
.Build();
|
||||
|
||||
var doneEvent = new ManualResetEventSlim();
|
||||
var lifetime = _host.Services.GetService<IHostApplicationLifetime>();
|
||||
|
|
@ -167,17 +175,6 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
|
|||
WebCoreLock.Release();
|
||||
}
|
||||
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.Map("/start", builder => builder.Run(context => context.Response.WriteAsync("Done")));
|
||||
_appBuilder(app);
|
||||
}
|
||||
|
||||
private delegate int hostfxr_main_fn(IntPtr argc, IntPtr argv);
|
||||
|
||||
[DllImport(HWebCoreDll)]
|
||||
|
|
@ -195,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
|
|||
[DllImport(InProcessHandlerDll)]
|
||||
private static extern int set_main_handler(hostfxr_main_fn main);
|
||||
|
||||
[DllImport("kernel32", SetLastError=true, CharSet = CharSet.Ansi)]
|
||||
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
|
||||
private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);
|
||||
|
||||
private void Retry(Action func, int attempts)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
|
@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Http;
|
|||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Server.IISIntegration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace IISSample
|
||||
|
|
@ -88,19 +90,23 @@ namespace IISSample
|
|||
});
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
public static Task Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuidler =>
|
||||
{
|
||||
webHostBuidler
|
||||
.UseKestrel()
|
||||
.UseStartup<Startup>();
|
||||
})
|
||||
.ConfigureLogging((_, factory) =>
|
||||
{
|
||||
factory.AddConsole();
|
||||
factory.AddFilter("Console", level => level >= LogLevel.Debug);
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
return host.RunAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||
|
|
@ -12,19 +14,27 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
public class IISExtensionTests
|
||||
{
|
||||
[Fact]
|
||||
public void CallingUseIISIntegrationMultipleTimesWorks()
|
||||
public async Task CallingUseIISIntegrationMultipleTimesWorks()
|
||||
{
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.UseIISIntegration()
|
||||
.Configure(app => { })
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.UseIISIntegration()
|
||||
.Configure(app => { });
|
||||
var server = new TestServer(builder);
|
||||
var server = host.GetTestServer();
|
||||
|
||||
var filters = server.Host.Services.GetServices<IStartupFilter>()
|
||||
await host.StartAsync();
|
||||
|
||||
var filters = server.Services.GetServices<IStartupFilter>()
|
||||
.OfType<IISSetupFilter>();
|
||||
|
||||
Assert.Single(filters);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
|
@ -12,6 +11,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.AspNetCore.Http.Features.Authentication;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Xunit;
|
||||
|
|
@ -25,21 +25,30 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var assertsExecuted = false;
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
var auth = context.Features.Get<IHttpAuthenticationFeature>();
|
||||
Assert.Null(auth);
|
||||
assertsExecuted = true;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
webHostBuilder
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
var auth = context.Features.Get<IHttpAuthenticationFeature>();
|
||||
Assert.Null(auth);
|
||||
assertsExecuted = true;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var req = new HttpRequestMessage(HttpMethod.Get, "");
|
||||
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
@ -53,22 +62,31 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var assertsExecuted = false;
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
var auth = context.Features.Get<IHttpAuthenticationFeature>();
|
||||
Assert.Null(auth);
|
||||
assertsExecuted = true;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
var auth = context.Features.Get<IHttpAuthenticationFeature>();
|
||||
Assert.Null(auth);
|
||||
assertsExecuted = true;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var req = new HttpRequestMessage(HttpMethod.Get, "");
|
||||
var response = await server.CreateClient().SendAsync(req);
|
||||
|
|
@ -85,23 +103,32 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", pathBase)
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
|
||||
appLifetime.ApplicationStopping.Register(() => applicationStoppingFired.SetResult(0));
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", pathBase)
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
|
||||
appLifetime.ApplicationStopping.Register(() => applicationStoppingFired.SetResult(0));
|
||||
|
||||
app.Run(context =>
|
||||
{
|
||||
requestExecuted.SetResult(0);
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
app.Run(context =>
|
||||
{
|
||||
requestExecuted.SetResult(0);
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, requestPath);
|
||||
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
@ -135,23 +162,32 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
|
||||
appLifetime.ApplicationStopping.Register(() => applicationStoppingFired.SetResult(0));
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
|
||||
appLifetime.ApplicationStopping.Register(() => applicationStoppingFired.SetResult(0));
|
||||
|
||||
app.Run(context =>
|
||||
{
|
||||
requestExecuted.SetResult(0);
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
app.Run(context =>
|
||||
{
|
||||
requestExecuted.SetResult(0);
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var request = new HttpRequestMessage(method, "/iisintegration");
|
||||
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
@ -171,23 +207,32 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
|
||||
appLifetime.ApplicationStopping.Register(() => applicationStoppingFired.SetResult(0));
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
|
||||
appLifetime.ApplicationStopping.Register(() => applicationStoppingFired.SetResult(0));
|
||||
|
||||
app.Run(context =>
|
||||
{
|
||||
requestExecuted.SetResult(0);
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
app.Run(context =>
|
||||
{
|
||||
requestExecuted.SetResult(0);
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, path);
|
||||
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
@ -207,23 +252,32 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
|
||||
appLifetime.ApplicationStopping.Register(() => applicationStoppingFired.SetResult(0));
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
|
||||
appLifetime.ApplicationStopping.Register(() => applicationStoppingFired.SetResult(0));
|
||||
|
||||
app.Run(context =>
|
||||
{
|
||||
requestExecuted.SetResult(0);
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
app.Run(context =>
|
||||
{
|
||||
requestExecuted.SetResult(0);
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "/iisintegration");
|
||||
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
@ -236,43 +290,63 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void UrlDelayRegisteredAndPreferHostingUrlsSet()
|
||||
public async Task UrlDelayRegisteredAndPreferHostingUrlsSet()
|
||||
{
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(context => Task.FromResult(0));
|
||||
});
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(context => Task.FromResult(0));
|
||||
});
|
||||
|
||||
Assert.Null(builder.GetSetting(WebHostDefaults.ServerUrlsKey));
|
||||
Assert.Null(builder.GetSetting(WebHostDefaults.PreferHostingUrlsKey));
|
||||
Assert.Null(webHostBuilder.GetSetting(WebHostDefaults.ServerUrlsKey));
|
||||
Assert.Null(webHostBuilder.GetSetting(WebHostDefaults.PreferHostingUrlsKey));
|
||||
|
||||
// Adds a server and calls Build()
|
||||
var server = new TestServer(builder);
|
||||
webHostBuilder.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
Assert.Equal("http://127.0.0.1:12345", builder.GetSetting(WebHostDefaults.ServerUrlsKey));
|
||||
Assert.Equal("true", builder.GetSetting(WebHostDefaults.PreferHostingUrlsKey));
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var configuration = host.Services.GetService<IConfiguration>();
|
||||
|
||||
Assert.Equal("http://127.0.0.1:12345", configuration[WebHostDefaults.ServerUrlsKey]);
|
||||
Assert.Equal("true", configuration[WebHostDefaults.PreferHostingUrlsKey]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PathBaseHiddenFromServer()
|
||||
public async Task PathBaseHiddenFromServer()
|
||||
{
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/pathBase")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(context => Task.FromResult(0));
|
||||
});
|
||||
new TestServer(builder);
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/pathBase")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(context => Task.FromResult(0));
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
Assert.Equal("http://127.0.0.1:12345", builder.GetSetting(WebHostDefaults.ServerUrlsKey));
|
||||
host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var configuration = host.Services.GetService<IConfiguration>();
|
||||
Assert.Equal("http://127.0.0.1:12345", configuration[WebHostDefaults.ServerUrlsKey]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -280,21 +354,30 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var requestPathBase = string.Empty;
|
||||
var requestPath = string.Empty;
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/pathbase")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
requestPathBase = context.Request.PathBase.Value;
|
||||
requestPath = context.Request.Path.Value;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/pathbase")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
requestPathBase = context.Request.PathBase.Value;
|
||||
requestPath = context.Request.Path.Value;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, "/PathBase/Path");
|
||||
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
@ -309,24 +392,33 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var assertsExecuted = false;
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
var auth = context.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>();
|
||||
var windows = await auth.GetSchemeAsync(IISDefaults.AuthenticationScheme);
|
||||
Assert.NotNull(windows);
|
||||
Assert.Null(windows.DisplayName);
|
||||
Assert.Equal("Microsoft.AspNetCore.Server.IISIntegration.AuthenticationHandler", windows.HandlerType.FullName);
|
||||
assertsExecuted = true;
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
var auth = context.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>();
|
||||
var windows = await auth.GetSchemeAsync(IISDefaults.AuthenticationScheme);
|
||||
Assert.NotNull(windows);
|
||||
Assert.Null(windows.DisplayName);
|
||||
Assert.Equal("Microsoft.AspNetCore.Server.IISIntegration.AuthenticationHandler", windows.HandlerType.FullName);
|
||||
assertsExecuted = true;
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var req = new HttpRequestMessage(HttpMethod.Get, "");
|
||||
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
@ -342,11 +434,36 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var assertsExecuted = false;
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
var auth = context.RequestServices.GetService<IAuthenticationSchemeProvider>();
|
||||
Assert.NotNull(auth);
|
||||
var windowsAuth = await auth.GetSchemeAsync(IISDefaults.AuthenticationScheme);
|
||||
if (forward)
|
||||
{
|
||||
Assert.NotNull(windowsAuth);
|
||||
Assert.Null(windowsAuth.DisplayName);
|
||||
Assert.Equal("AuthenticationHandler", windowsAuth.HandlerType.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Null(windowsAuth);
|
||||
}
|
||||
assertsExecuted = true;
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.Configure<IISOptions>(options =>
|
||||
|
|
@ -354,27 +471,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
options.ForwardWindowsAuthentication = forward;
|
||||
});
|
||||
})
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
var auth = context.RequestServices.GetService<IAuthenticationSchemeProvider>();
|
||||
Assert.NotNull(auth);
|
||||
var windowsAuth = await auth.GetSchemeAsync(IISDefaults.AuthenticationScheme);
|
||||
if (forward)
|
||||
{
|
||||
Assert.NotNull(windowsAuth);
|
||||
Assert.Null(windowsAuth.DisplayName);
|
||||
Assert.Equal("AuthenticationHandler", windowsAuth.HandlerType.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Null(windowsAuth);
|
||||
}
|
||||
assertsExecuted = true;
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var req = new HttpRequestMessage(HttpMethod.Get, "");
|
||||
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
@ -390,11 +491,24 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
var assertsExecuted = false;
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
using var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseSetting("TOKEN", "TestToken")
|
||||
.UseSetting("PORT", "12345")
|
||||
.UseSetting("APPL_PATH", "/")
|
||||
.UseIISIntegration()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
assertsExecuted = true;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
})
|
||||
.UseTestServer();
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.Configure<IISOptions>(options =>
|
||||
|
|
@ -402,15 +516,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
options.ForwardWindowsAuthentication = forward;
|
||||
});
|
||||
})
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
assertsExecuted = true;
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
});
|
||||
var server = new TestServer(builder);
|
||||
.Build();
|
||||
|
||||
var server = host.GetTestServer();
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
var req = new HttpRequestMessage(HttpMethod.Get, "");
|
||||
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
|
||||
|
|
|
|||
Loading…
Reference in New Issue