Skip to content

Commit e84773d

Browse files
authored
[6.0] Restore IISServerSetupFilter server type check (#45036)
* Restore IISServerSetupFilter server type check * Fix example
1 parent 7ab0b70 commit e84773d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/Servers/IIS/IIS/src/Core/IISHttpContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ protected void InitializeContext()
239239
else
240240
{
241241
// Mismatch, fall back
242-
// The failing test case here is "/base/call//../ball//path1//path2", reduced to "/base/call/ball//path1//path2",
242+
// The failing test case here is "/base/call//../bat//path1//path2", reduced to "/base/call/bat//path1//path2",
243243
// where http.sys collapses "//" before "../", but we do "../" first. We've lost the context that there were dot segments,
244244
// or duplicate slashes, how do we figure out that "call/" can be eliminated?
245245
originalOffset = 0;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Microsoft.AspNetCore.Builder;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Hosting.Server;
9+
using Microsoft.AspNetCore.Hosting.Server.Features;
10+
using Microsoft.Extensions.DependencyInjection;
11+
12+
namespace Microsoft.AspNetCore.Server.IIS.Core
13+
{
14+
internal class IISServerSetupFilter : IStartupFilter
15+
{
16+
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
17+
{
18+
return app =>
19+
{
20+
var server = app.ApplicationServices.GetService<IServer>();
21+
if (server?.GetType() != typeof(IISHttpServer))
22+
{
23+
throw new InvalidOperationException("Application is running inside IIS process but is not configured to use IIS server.");
24+
}
25+
26+
next(app);
27+
};
28+
}
29+
}
30+
}

src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder)
4242
services.AddSingleton(new IISNativeApplication(new NativeSafeHandle(iisConfigData.pNativeApplication)));
4343
services.AddSingleton<IServer, IISHttpServer>();
4444
services.AddTransient<IISServerAuthenticationHandlerInternal>();
45+
services.AddSingleton<IStartupFilter, IISServerSetupFilter>();
4546
services.AddAuthenticationCore();
4647
services.AddSingleton<IServerIntegratedAuth>(_ => new ServerIntegratedAuth()
4748
{

0 commit comments

Comments
 (0)