Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\..\..\build\testsite.props" />

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<TargetFrameworks>$(DefaultNetCoreTargetFramework);$(NetMinimum)</TargetFrameworks>
<AssemblyName>InProcessWebSite</AssemblyName>
<DefineConstants>FORWARDCOMPAT</DefineConstants>
<CompileUsingReferenceAssemblies>false</CompileUsingReferenceAssemblies>
Expand All @@ -27,38 +27,25 @@
<None Include="..\InProcessWebSite\web.config" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<!-- This package is hard-coded to the 2.2.0 package as a part of ensuring ANCM stays forward compatible. -->
<PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.6">
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<PropertyGroup Condition="'$(TargetFramework)' == '$(NetMinimum)'">
<UseAspNetCoreSharedRuntime>true</UseAspNetCoreSharedRuntime>
<DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp>true</DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">
<Reference Include="Microsoft.AspNetCore.Server.IIS" />
<Reference Include="Microsoft.AspNetCore.Hosting" />
<Reference Include="Microsoft.AspNetCore.ResponseCompression" />
<Reference Include="Microsoft.AspNetCore.Server.IISIntegration" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel.Core" />
<Reference Include="Microsoft.AspNetCore.HttpsPolicy" />
<Reference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<Reference Include="Microsoft.Extensions.Configuration.Json" />
<Reference Include="Microsoft.Extensions.Logging.Console" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.0" >
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" >
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.2.0" >
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" >
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" >
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" >
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" >
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" >
<AllowExplicitReference>true</AllowExplicitReference>
</PackageReference>
<Reference Include="xunit.assert" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void WebSocketEcho(IApplicationBuilder app)
{
var ws = await Upgrade(context);
#if FORWARDCOMPAT
var appLifetime = app.ApplicationServices.GetRequiredService<Microsoft.AspNetCore.Hosting.IApplicationLifetime>();
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
#else
var appLifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
#endif
Expand Down Expand Up @@ -95,6 +95,8 @@ private void WebSocketLifetimeEvents(IApplicationBuilder app)

private void WebSocketUpgradeFails(IApplicationBuilder app)
{
// Suppress false positive. https://github.com/dotnet/aspnetcore/issues/64173
#pragma warning disable ASP0016 // The method used to create a RequestDelegate returns Task<System.IO.Stream>
app.Run(async context =>
{
var upgradeFeature = context.Features.Get<IHttpUpgradeFeature>();
Expand All @@ -105,6 +107,7 @@ private void WebSocketUpgradeFails(IApplicationBuilder app)
throw new InvalidOperationException("Unexpected error from UpgradeAsync.");
}
});
#pragma warning restore ASP0016 // The method used to create a RequestDelegate returns Task<System.IO.Stream>
}

#if !FORWARDCOMPAT
Expand Down
18 changes: 11 additions & 7 deletions src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public void ConfigureServices(IServiceCollection serviceCollection)
serviceCollection.AddHttpContextAccessor();
}
#if FORWARDCOMPAT
private async Task ContentRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().ContentRootPath);
private async Task ContentRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<IWebHostEnvironment>().ContentRootPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we revert this and suppress the analyzer warnings here too? I think the #if and the #else branches are currently identical.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with that - I was gonna trim it down to 1 branch, but I figured it'd be reasonable to keep the 2 in case the older & newer TFMs have different API surface. You want me to push a commit or were you already doing it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want me to push a commit or were you already doing it?

No. I haven't started it. And I think you're right that trimming it down to 1 branch makes more sense if that's possible. I think the FORWARDCOMPAT constant was mostly added to avoid build time errors on down-level frameworks that didn't have the new types. Now that net8.0 is the minimum TFM, most if not all of it is probably unnecessary.


private async Task WebRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().WebRootPath);
private async Task WebRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<IWebHostEnvironment>().WebRootPath);
#else
private async Task ContentRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<IWebHostEnvironment>().ContentRootPath);

Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task WaitingRequestCount(HttpContext context)
public Task CreateFile(HttpContext context)
{
#if FORWARDCOMPAT
var hostingEnv = context.RequestServices.GetService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>();
var hostingEnv = context.RequestServices.GetService<IWebHostEnvironment>();
#else
var hostingEnv = context.RequestServices.GetService<IWebHostEnvironment>();
#endif
Expand Down Expand Up @@ -474,6 +474,8 @@ private Task TestRequestHeaders(HttpContext ctx)
return ctx.Response.WriteAsync($"Failure: '{headerName}' TryGetValue");
}

// ASP0019 recommends using Append or the indexer over Add, because it throws, but we're testing that behavior here.
#pragma warning disable ASP0019 // Use IHeaderDictionary.Append or the indexer to append or set headers
// Both default and StringValues.Empty should unset the header, allowing it to be added again.
ArgumentException duplicateKeyException = null;
ctx.Request.Headers.Add(headerName, "test");
Expand All @@ -492,6 +494,7 @@ private Task TestRequestHeaders(HttpContext ctx)
duplicateKeyException = ex;
ctx.Request.Headers[headerName] = default;
}
#pragma warning restore ASP0019 // Use IHeaderDictionary.Append or the indexer to append or set headers

if (duplicateKeyException is null)
{
Expand Down Expand Up @@ -597,7 +600,7 @@ private async Task WaitForAppToStartShuttingDown(HttpContext ctx)
{
await ctx.Response.WriteAsync("test1");
#if FORWARDCOMPAT
var lifetime = ctx.RequestServices.GetService<Microsoft.AspNetCore.Hosting.IApplicationLifetime>();
var lifetime = ctx.RequestServices.GetService<IHostApplicationLifetime>();
#else
var lifetime = ctx.RequestServices.GetService<IHostApplicationLifetime>();
#endif
Expand Down Expand Up @@ -680,8 +683,9 @@ private async Task ReadAndWriteEchoLines(HttpContext ctx)
private async Task ReadAndWriteEchoLinesNoBuffering(HttpContext ctx)
{
#if FORWARDCOMPAT
var feature = ctx.Features.Get<IHttpBufferingFeature>();
feature.DisableResponseBuffering();
var feature = ctx.Features.Get<IHttpResponseBodyFeature>();
feature.DisableBuffering();
Assert.True(ctx.Request.CanHaveBody());
#else
var feature = ctx.Features.Get<IHttpResponseBodyFeature>();
feature.DisableBuffering();
Expand Down Expand Up @@ -993,7 +997,7 @@ private async Task Shutdown(HttpContext ctx)
{
await ctx.Response.WriteAsync("Shutting down");
#if FORWARDCOMPAT
ctx.RequestServices.GetService<Microsoft.AspNetCore.Hosting.IApplicationLifetime>().StopApplication();
ctx.RequestServices.GetService<IHostApplicationLifetime>().StopApplication();
#else
ctx.RequestServices.GetService<IHostApplicationLifetime>().StopApplication();
#endif
Expand Down
Loading