Skip to content

Commit

Permalink
[6.0] Restore IISServerSetupFilter server type check (#45036)
Browse files Browse the repository at this point in the history
* Restore IISServerSetupFilter server type check

* Fix example
  • Loading branch information
Tratcher authored Nov 14, 2022
1 parent 7ab0b70 commit e84773d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Servers/IIS/IIS/src/Core/IISHttpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected void InitializeContext()
else
{
// Mismatch, fall back
// The failing test case here is "/base/call//../ball//path1//path2", reduced to "/base/call/ball//path1//path2",
// The failing test case here is "/base/call//../bat//path1//path2", reduced to "/base/call/bat//path1//path2",
// where http.sys collapses "//" before "../", but we do "../" first. We've lost the context that there were dot segments,
// or duplicate slashes, how do we figure out that "call/" can be eliminated?
originalOffset = 0;
Expand Down
30 changes: 30 additions & 0 deletions src/Servers/IIS/IIS/src/Core/IISServerSetupFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.Server.IIS.Core
{
internal 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);
};
}
}
}
1 change: 1 addition & 0 deletions src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder)
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()
{
Expand Down

0 comments on commit e84773d

Please sign in to comment.