diff options
author | Chris R <Tratcher@outlook.com> | 2022-11-11 22:43:51 +0300 |
---|---|---|
committer | Chris R <Tratcher@outlook.com> | 2022-11-11 22:45:48 +0300 |
commit | d15a730394403fea0c5d7efd46d2f06443b8b136 (patch) | |
tree | 75e9d8565db60ea676601640dd1d59d3d3bd7ef8 | |
parent | 0dbfa9fb50492d66440d04b370ea73afe7e81f45 (diff) |
Restore IISServerSetupFilter server type check
-rw-r--r-- | src/Servers/IIS/IIS/src/Core/IISServerSetupFilter.cs | 26 | ||||
-rw-r--r-- | src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/Servers/IIS/IIS/src/Core/IISServerSetupFilter.cs b/src/Servers/IIS/IIS/src/Core/IISServerSetupFilter.cs new file mode 100644 index 0000000000..97a0f0e3b4 --- /dev/null +++ b/src/Servers/IIS/IIS/src/Core/IISServerSetupFilter.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Server.IIS.Core; + +internal sealed class IISServerSetupFilter : IStartupFilter +{ + public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) + { + return app => + { + var server = app.ApplicationServices.GetService<IServer>(); + if (server?.GetType() != typeof(IISHttpServer)) + { + throw new InvalidOperationException("Application is running inside IIS process but is not configured to use IIS server."); + } + + next(app); + }; + } +} diff --git a/src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs b/src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs index bb6be412e3..302f1af5a6 100644 --- a/src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs +++ b/src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs @@ -37,6 +37,7 @@ public static class WebHostBuilderIISExtensions services.AddSingleton(new IISNativeApplication(new NativeSafeHandle(iisConfigData.pNativeApplication))); services.AddSingleton<IServer, IISHttpServer>(); services.AddTransient<IISServerAuthenticationHandlerInternal>(); + services.AddSingleton<IStartupFilter, IISServerSetupFilter>(); services.AddAuthenticationCore(); services.AddSingleton<IServerIntegratedAuth>(_ => new ServerIntegratedAuth() { |