asp.net-mvc-4 - 捕获并记录有关 "Minification failed. Returning unminified contents"的 MVC4 消息

标签 asp.net-mvc-4 bundling-and-minification asp.net-optimization

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

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

很高兴的是,当出现错误时,捆绑程序会返回原始内容,这样我的网站就不会中断,但我想自动了解这些错误,而不是必须访问每个 css/js bundle url 来查看是否有错误。

最佳答案

因此,该逻辑实际上是在 Script/StyleBundle 使用的默认转换的实现中。如果您想自己捕获这些错误,您可以将 bundle 上的转换更改为显示这些错误的内容:

因此,要实际检测错误,您必须手动枚举所有包(以触发它们生成),并且还能够监听发生的错误(因此下面的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;
    }

关于asp.net-mvc-4 - 捕获并记录有关 "Minification failed. Returning unminified contents"的 MVC4 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18906715/

相关文章:

asp.net-mvc - 使用 TFS2012 构建 .net 4.0 代码

webpack-2 - 未使用 extract-text-webpack-plugin 提取公共(public) block 的 CSS

asp.net-mvc - MVC4 捆绑通配符 - * 与 {version}

asp.net-mvc - MVC Bundling 通过删除空格来破坏我的 calc CSS 语句?

javascript - 盒式 bundle 与 MVC4 bundle

asp.net-mvc - 如何指定显式 ScriptBundle 包含顺序?

asp.net-mvc-4 - bundle (System.Web.Optimization) 如何生成捆绑链接的构建指纹?

asp.net-mvc - MVC 4 HiddenFor 字段未出现在呈现的标记中

c# - 为一种方法覆盖 MVC 中的全局过滤器

mysql - 我应该使用哪种连接? 【EF4.0代码优先】