diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperModule.cs b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperModule.cs index 7dad941c5..0283ffba6 100644 --- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperModule.cs +++ b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperModule.cs @@ -8,6 +8,7 @@ using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.ApiExploring; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.AspNetCore.Mvc.ProxyScripting; +using Volo.Abp.Content; using Volo.Abp.Http.Modeling; using Volo.Abp.Localization; using Volo.Abp.Modularity; @@ -47,6 +48,8 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper options.IgnoreReturnTypes.Add(); // api/abp/application-configuration options.IgnoreReturnTypes.Add(); + // + options.IgnoreReturnTypes.Add(); // Abp/ServiceProxyScript options.IgnoreControllers.Add(); diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs index 4df387198..6a62f7589 100644 --- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs +++ b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs @@ -21,15 +21,6 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling [ExposeServices(typeof(AbpExceptionPageFilter))] public class AbpExceptionPageWrapResultFilter: AbpExceptionPageFilter, ITransientDependency { - protected override bool ShouldHandleException(PageHandlerExecutingContext context) - { - if (context.ActionDescriptor.CanWarpRsult()) - { - return true; - } - return base.ShouldHandleException(context); - } - protected override async Task HandleAndWrapException(PageHandlerExecutedContext context) { var wrapResultChecker = context.GetRequiredService(); diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs index 96c13e746..e5bf849d8 100644 --- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs +++ b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs @@ -22,19 +22,15 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling [ExposeServices(typeof(AbpExceptionFilter))] public class AbpExceptionWrapResultFilter : AbpExceptionFilter, ITransientDependency { - protected override bool ShouldHandleException(ExceptionContext context) + protected override async Task HandleAndWrapException(ExceptionContext context) { var wrapResultChecker = context.GetRequiredService(); - if (wrapResultChecker.WrapOnException(context)) + if (!wrapResultChecker.WrapOnException(context)) { - return true; + await base.HandleAndWrapException(context); + return; } - return base.ShouldHandleException(context); - } - - protected override async Task HandleAndWrapException(ExceptionContext context) - { //TODO: Trigger an AbpExceptionHandled event or something like that. var wrapResultOptions = context.GetRequiredService>().Value; var exceptionHandlingOptions = context.GetRequiredService>().Value; diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs index 239a28657..e6861de37 100644 --- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs +++ b/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Reflection; using Volo.Abp.DependencyInjection; using Volo.Abp.Http; +using Volo.Abp.Threading; namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper { @@ -126,13 +127,14 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper protected virtual bool CheckForReturnType(ControllerActionDescriptor controllerActionDescriptor) { - if (controllerActionDescriptor.MethodInfo.ReturnType.IsDefined(typeof(IgnoreWrapResultAttribute), true)) + var returnType = AsyncHelper.UnwrapTask(controllerActionDescriptor.MethodInfo.ReturnType); + + if (returnType.IsDefined(typeof(IgnoreWrapResultAttribute), true)) { return false; } - return !Options.IgnoreReturnTypes.Any(type => - controllerActionDescriptor.MethodInfo.ReturnType.IsAssignableFrom(type)); + return !Options.IgnoreReturnTypes.Any(type => returnType.IsAssignableFrom(type)); } protected virtual bool CheckForException(Exception exception) diff --git a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 5653cc27f..27229a7a9 100644 --- a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -15,6 +15,7 @@ using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Security.Claims; using Volo.Abp.AspNetCore.TestBase; using Volo.Abp.Autofac; +using Volo.Abp.Content; using Volo.Abp.GlobalFeatures; using Volo.Abp.Localization; using Volo.Abp.Localization.ExceptionHandling; @@ -84,6 +85,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc options.IgnoreControllers.Add(); // api/abp/application-configuration options.IgnoreReturnTypes.Add(); + options.IgnoreReturnTypes.Add(); options.IgnorePrefixUrls.Add("/api/dont/wrap-result-test"); diff --git a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController.cs b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController.cs index 62eb03c99..5412fb329 100644 --- a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController.cs +++ b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController.cs @@ -4,8 +4,12 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Data.Common; +using System.IO; +using System.Text; +using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Content; namespace LINGYUN.Abp.AspNetCore.Mvc.Results { @@ -17,6 +21,18 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Results LocalizationResource = typeof(MvcTestResource); } + [HttpGet] + [Route("get-text")] + public async Task DontWrapRemoteStreamContext() + { + var textBytes = Encoding.UTF8.GetBytes("text"); + + var memoryStream = new MemoryStream(); + await memoryStream.WriteAsync(textBytes); + + return new RemoteStreamContent(memoryStream); + } + [HttpGet] [Route("exception")] public TestResultObject WrapBusinessException() diff --git a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs index b33924693..165fa5b57 100644 --- a/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs +++ b/aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs @@ -11,6 +11,14 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Results { public class WrapResultController_Tests : AbpAspNetCoreMvcTestBase { + [Fact] + public async Task Should_Return_Not_Wrap_Result_For_Abp_Remote_Stream_Content() + { + var result = await GetResponseAsStringAsync("/api/wrap-result-test/get-text"); + result.ShouldNotBeNull(); + result.ShouldBe("text"); + } + [Fact] public async Task Should_Return_Not_Wrap_Result_For_Abp_Api_Definition() {