Taritsyn / WebMarkupMin

The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
Apache License 2.0
447 stars 48 forks source link

Filtering is not allowed #2

Closed timgaunt closed 8 years ago

timgaunt commented 8 years ago

Running WebMarkupMin.AspNet4.Mvc v2.0.0-rc1 on Umbraco Cms 6.2.5 (https://www.nuget.org/packages/UmbracoCms/6.2.5) with MinifyHtmlAttribute/MinifyXmlAttribute/CompressContentAttribute enabled we're getting "Filtering is not allowed" on one or two actions.

What's interesting is the module appears to be working generally throughout the site, it's even been working on this action before a recent build (that included no related changes).

Full stack trace is below:

Server Error in '/' Application.

  Filtering is not allowed.

  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

  Exception Details: System.Web.HttpException: Filtering is not allowed.

  Source Error: 

  Line 3:      Layout = "_MyAccount.cshtml";
  Line 4:  }
  Line 5:  @Html.Action("TrackedItems", "MyAccount")

  Source File: x:\xxx\www\Views\TrackedItems.cshtml    Line: 5 

  Stack Trace: 

  [HttpException (0x80004005): Filtering is not allowed.]
     System.Web.HttpResponse.set_Filter(Stream value) +3468372
     System.Web.HttpResponseWrapper.set_Filter(Stream value) +14
     WebMarkupMin.AspNet4.Mvc.CompressContentAttribute.OnResultExecuted(ResultExecutedContext filterContext) +123
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +231
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
     System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +75
     System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
     System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
     System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
     System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
     System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
     System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
     System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
     System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
     System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
     System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
     System.Web.Mvc.<>c__DisplayClassa.<EndProcessRequest>b__9() +22
     System.Web.Mvc.<>c__DisplayClass4.<Wrap>b__3() +10
     System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +53
     System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Action action) +64
     System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.EndProcessRequest(IAsyncResult result) +71
     System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1114

  [HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
     System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3450725
     System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +77
     System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +29
     System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +24
     System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +463
     System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +83
     System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName) +10
     ASP._Page_Views_TrackedItems_cshtml.Execute() in x:\xxx\www\Views\TrackedItems.cshtml:5
     System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198
     System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
     System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
     System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +234
     System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
     Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) in d:\Dev\Umbraco6\src\Umbraco.Core\Profiling\ProfilingView.cs:24
     StackExchange.Profiling.MVCHelpers.WrappedView.Render(ViewContext viewContext, TextWriter writer) in c:\Code\github\SamSaffron\MiniProfiler\StackExchange.Profiling\MVCHelpers\WrappedView.cs:58
     System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
     System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
     System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
     System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +75
     System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
     System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
     System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
     System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
     System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
     System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
     System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
     System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
     System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +16
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
     System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9742689
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

  Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1038.0
Taritsyn commented 8 years ago

Very similar to conflict of the response filters. It is also possible, that the filters specified in wrong order.

Give me an example of FilterConfig.cs file and the problematic MVC action.

timgaunt commented 8 years ago

Sure, although it's working on other pages on the site (same code base -and has worked on this page before...!?!)

        GlobalFilters.Filters.Add(new MinifyHtmlAttribute());
        GlobalFilters.Filters.Add(new MinifyXmlAttribute());
        GlobalFilters.Filters.Add(new CompressContentAttribute());
Taritsyn commented 8 years ago

Try the following:

GlobalFilters.Filters.Add(new CompressContentAttribute());
GlobalFilters.Filters.Add(new MinifyHtmlAttribute());
GlobalFilters.Filters.Add(new MinifyXmlAttribute());
timgaunt commented 8 years ago

Done and no luck, I've even removed any other filters that were around in the project without any benefit.

timgaunt commented 8 years ago

I've found the issue (and this is an interesting one).

In short, we'd renamed an action that was being referenced on the page, when I disabled the filter completely I get the error "A public action method 'ActionName' was not found on controller 'xxx.www.Controllers.SomeController'." which when resolved makes the system "just work".

Could it be that it's trying to minify responses with response codes != 200?

Taritsyn commented 8 years ago

Could it be that it's trying to minify responses with response codes != 200?

In this case, is performed compression only. Will fix in next release.

Taritsyn commented 8 years ago

In WebMarkupMin 2.0.0 RC 3 fixed this error.

maleki1393 commented 4 years ago

i use GlobalFilters.Filters.Add(new CompressContentAttribute()); GlobalFilters.Filters.Add(new MinifyHtmlAttribute()); GlobalFilters.Filters.Add(new MinifyXmlAttribute()); now i want exclude one action from it please guide me

Taritsyn commented 4 years ago

Hello, Mahmoud!

Read the “ASP.NET Extensions > Managers and options” subsection and “ASP.NET 4.X Extensions” section of documentation.