From 826026021c32fc17ac0fb8df818e73c2a3012aad Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 2 Nov 2026 17:45:59 +0800 Subject: [PATCH 1/2] Disable static asset compression on .NET 11 RC SDKs --- .../buildTransitive/Volo.Abp.AspNetCore.targets | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/framework/src/Volo.Abp.AspNetCore/buildTransitive/Volo.Abp.AspNetCore.targets b/framework/src/Volo.Abp.AspNetCore/buildTransitive/Volo.Abp.AspNetCore.targets index 8dfab9ff6e..ac2b3a951d 100644 --- a/framework/src/Volo.Abp.AspNetCore/buildTransitive/Volo.Abp.AspNetCore.targets +++ b/framework/src/Volo.Abp.AspNetCore/buildTransitive/Volo.Abp.AspNetCore.targets @@ -5,4 +5,10 @@ false + + + + false + From 0349ddde8562972dc9591c491eb731db83e5f305 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 2 Nov 2026 19:14:22 +0800 Subject: [PATCH 2/2] Read the websocket feature without writing to the HttpContext feature collection --- .../Auditing/AspNetCoreAuditLogContributor.cs | 5 +- ...eUnitOfWorkTransactionBehaviourProvider.cs | 5 +- ...fWorkTransactionBehaviourProvider_Tests.cs | 90 +++++++++++++++++++ 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AspNetCoreAuditLogContributor.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AspNetCoreAuditLogContributor.cs index becdee806d..bce8440098 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AspNetCoreAuditLogContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AspNetCoreAuditLogContributor.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Text; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -30,7 +31,9 @@ public class AspNetCoreAuditLogContributor : AuditLogContributor, ITransientDepe return; } - if (httpContext.WebSockets.IsWebSocketRequest) + // HttpContext.WebSockets writes to the feature collection on every read when the request has no + // websocket feature, which breaks other threads reading the same HttpContext (e.g. Blazor prerendering). + if (httpContext.Features.Get()?.IsWebSocketRequest == true) { return; } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Uow/AspNetCoreUnitOfWorkTransactionBehaviourProvider.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Uow/AspNetCoreUnitOfWorkTransactionBehaviourProvider.cs index e323b323d1..f3ad8a8a75 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Uow/AspNetCoreUnitOfWorkTransactionBehaviourProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Uow/AspNetCoreUnitOfWorkTransactionBehaviourProvider.cs @@ -1,5 +1,6 @@ using System; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using Volo.Abp.Http; @@ -20,7 +21,9 @@ public class AspNetCoreUnitOfWorkTransactionBehaviourProvider : IUnitOfWorkTrans return null; } - if (httpContext.WebSockets.IsWebSocketRequest) + // HttpContext.WebSockets writes to the feature collection on every read when the request has no + // websocket feature, which breaks other threads reading the same HttpContext (e.g. Blazor prerendering). + if (httpContext.Features.Get()?.IsWebSocketRequest == true) { return null; } diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Uow/AspNetCoreUnitOfWorkTransactionBehaviourProvider_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Uow/AspNetCoreUnitOfWorkTransactionBehaviourProvider_Tests.cs index e5369e688e..203ab21559 100644 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Uow/AspNetCoreUnitOfWorkTransactionBehaviourProvider_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Uow/AspNetCoreUnitOfWorkTransactionBehaviourProvider_Tests.cs @@ -1,4 +1,11 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Net.WebSockets; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Options; using Shouldly; using Xunit; @@ -12,6 +19,11 @@ public class AspNetCoreUnitOfWorkTransactionBehaviourProvider_Tests var httpContext = new DefaultHttpContext(); httpContext.Request.Method = method; + return CreateProvider(httpContext); + } + + private static AspNetCoreUnitOfWorkTransactionBehaviourProvider CreateProvider(HttpContext httpContext) + { return new AspNetCoreUnitOfWorkTransactionBehaviourProvider( new HttpContextAccessor { HttpContext = httpContext }, Microsoft.Extensions.Options.Options.Create(new AspNetCoreUnitOfWorkTransactionBehaviourProviderOptions())); @@ -29,4 +41,82 @@ public class AspNetCoreUnitOfWorkTransactionBehaviourProvider_Tests { CreateProvider(method).IsTransactional.ShouldBe(expected); } + + [Fact] + public void IsTransactional_Should_Not_Change_The_Feature_Collection() + { + var features = new KestrelLikeFeatureCollection(); + features.Set(new HttpRequestFeature { Method = "GET", Path = "/" }); + features.Set(new HttpResponseFeature()); + features.Set(new StreamResponseBodyFeature(Stream.Null)); + var httpContext = new DefaultHttpContext(features); + var provider = CreateProvider(httpContext); + var revision = httpContext.Features.Revision; + + provider.IsTransactional.ShouldBe(false); + provider.IsTransactional.ShouldBe(false); + + httpContext.Features.Revision.ShouldBe(revision); + } + + [Fact] + public void IsTransactional_Should_Return_Null_For_WebSocket_Requests() + { + var httpContext = new DefaultHttpContext(); + httpContext.Request.Method = "GET"; + httpContext.Features.Set(new TestWebSocketFeature()); + + CreateProvider(httpContext).IsTransactional.ShouldBeNull(); + } + + // Kestrel's feature collection increments the revision on every Set, even when the value is null. + private sealed class KestrelLikeFeatureCollection : IFeatureCollection + { + private readonly FeatureCollection _inner = new(); + + public int Revision { get; private set; } + + public bool IsReadOnly => false; + + public object? this[Type key] + { + get => _inner[key]; + set + { + Revision++; + _inner[key] = value; + } + } + + public TFeature? Get() + { + return _inner.Get(); + } + + public void Set(TFeature? instance) + { + Revision++; + _inner.Set(instance); + } + + public IEnumerator> GetEnumerator() + { + return _inner.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + + private sealed class TestWebSocketFeature : IHttpWebSocketFeature + { + public bool IsWebSocketRequest => true; + + public Task AcceptAsync(WebSocketAcceptContext context) + { + throw new System.NotSupportedException(); + } + } }