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/