Asp.net mvc 4 捕获并记录有关“的MVC4消息”;缩小失败。“返回未统一的内容”;

Asp.net mvc 4 捕获并记录有关“的MVC4消息”;缩小失败。“返回未统一的内容”;,asp.net-mvc-4,bundling-and-minification,asp.net-optimization,Asp.net Mvc 4,Bundling And Minification,Asp.net Optimization,关于StackOverflow,有许多问题是关于缩小失败的。从MVC4缩小返回未统一的内容错误 我想知道是否有一种方法可以在发生此错误时得到通知并记录它 当出现错误时,bundler会返回原始内容,这样我的站点就不会崩溃,这很好,但是我想自动了解这些错误,而不必访问每个css/js包url以查看是否有错误。因此,脚本/样式包使用的默认转换的实现中实际上存在逻辑。如果您想自己捕获这些错误,可以将包上的转换更改为显示这些错误的内容: 因此,要真正检测错误,您必须手动枚举所有捆绑包(以触发它们生成),

关于StackOverflow,有许多问题是关于缩小失败的
。从MVC4缩小返回未统一的内容
错误

我想知道是否有一种方法可以在发生此错误时得到通知并记录它


当出现错误时,bundler会返回原始内容,这样我的站点就不会崩溃,这很好,但是我想自动了解这些错误,而不必访问每个css/js包url以查看是否有错误。

因此,脚本/样式包使用的默认转换的实现中实际上存在逻辑。如果您想自己捕获这些错误,可以将包上的转换更改为显示这些错误的内容:

因此,要真正检测错误,您必须手动枚举所有捆绑包(以触发它们生成),并能够侦听发生的错误(因此下面等效的GenerateErrorResponse需要将任何错误报告给您将看到的地方)

以下是JsMinify在其过程中所做的工作,以供参考:

    /// <summary>
    /// Transforms the bundle contents by applying javascript minification
    /// </summary>
    /// <param name="context">The <see cref="BundleContext"/> object that contains state for both the framework configuration and the HTTP request.</param>
    /// <param name="response">A <see cref="BundleResponse"/> object containing the bundle contents.</param>
    public virtual void Process(BundleContext context, BundleResponse response) {
        if (!context.EnableInstrumentation) {
            Minifier min = new Minifier();
            // NOTE: Eval immediate treatment is needed for WebUIValidation.js to work properly after minification
            // NOTE: CssMinify does not support important comments, so we are going to strip them in JS minification as well
            string minifiedJs = min.MinifyJavaScript(response.Content, new CodeSettings() { EvalTreatment = EvalTreatment.MakeImmediateSafe, PreserveImportantComments = false });
            if (min.ErrorList.Count > 0) {
                GenerateErrorResponse(response, min.ErrorList);
            }
            else {
                response.Content = minifiedJs;
            }
        }

        response.ContentType = JsContentType;
    }
//
///通过应用javascript缩小来转换包内容
/// 
///包含框架配置和HTTP请求状态的对象。
///包含包内容的对象。
公共虚拟无效进程(BundleContext、BundleResponse响应){
if(!context.EnableInstrumentation){
Minifier min=新的Minifier();
//注意:缩小后,WebUIValidation.js需要立即进行评估处理才能正常工作
//注意:CssMinify不支持重要的注释,所以我们也将在JS缩小中去掉它们
字符串minifiedJs=min.MinifyJavaScript(response.Content,new code设置(){evaltreaction=evaltreaction.MakeImmediateSafe,preserveinmportcomments=false});
如果(最小错误列表计数>0){
GenerateErrorResponse(响应,最小错误列表);
}
否则{
response.Content=minifiedJs;
}
}
response.ContentType=JsContentType;
}

@MikeSmithDev,我的意思是,当出现语法错误时,minifier足够好,可以返回原始CSS,因此,不破坏站点我希望有一个设置来切换错误是否冒泡/暴露,而不是重写代码。是否有其他方法可以查看响应内容并查找“缩小失败。返回未显示的内容”。错误消息?我认为响应。过滤器可能可以做到这一点。