asp.net-mvc - 捆绑和缩小没有呈现正确的路径

标签 asp.net-mvc asp.net-mvc-3 c#-4.0 asp.net-mvc-4 bundling-and-minification

我在使用 ASP.NET MVC 4 的捆绑和缩小功能时遇到问题基本上我有以下捆绑设置:

        bundles.Add(new StyleBundle("~/backendcss").Include(
                    "~/backendContent/bootstrap/css/bootstrap.min.css",
                    "~/backendContent/assets/jui/css/jquery-ui.css",
                    "~/backendContent/assets/jui/jquery-ui.custom.css",
                    "~/backendContent/plugins/uniform/css/uniform.default.css",
                    "~/backendContent/plugins/fullcalendar/fullcalendar.css",
                    "~/backendContent/plugins/fullcalendar/fullcalendar.print.css",
                    "~/backendContent/assets/css/fonts/icomoon/style.css",
                    "~/backendContent/assets/css/main-style.css",
                    "~/backendContent/plugins/pnotify/jquery.pnotify.css",
                    "~/backendContent/plugins/msgbox/jquery.msgbox.css",
                    "~/backendContent/IntroJS/css/introjs.css"));

当它们被放置在页面上时,它们会像这样出来:
<link href="/backendContent/assets/jui/css/jquery-ui.css" rel="stylesheet"/>
<link href="/backendContent/assets/jui/jquery-ui.custom.css" rel="stylesheet"/>
<link href="/backendContent/plugins/uniform/css/uniform.default.css" rel="stylesheet"/>
<link href="/backendContent/plugins/fullcalendar/fullcalendar.css" rel="stylesheet"/>
<link href="/backendContent/plugins/fullcalendar/fullcalendar.print.css" rel="stylesheet"/>
<link href="/backendContent/assets/css/fonts/icomoon/style.css" rel="stylesheet"/>
<link href="/backendContent/assets/css/main-style.css" rel="stylesheet"/>
<link href="/backendContent/plugins/pnotify/jquery.pnotify.css" rel="stylesheet"/>
<link href="/backendContent/plugins/msgbox/jquery.msgbox.css" rel="stylesheet"/>
<link href="/backendContent/IntroJS/css/introjs.css" rel="stylesheet"/>
  • 第一个问题是蒂尔达~没有出现在链接的开头,我认为这是问题之一(站点无法正确呈现)现在所有上述 css 样式表都在解决,但是有很多导入和相对 url(图像),我认为这些是搞砸了(没有包,如果我只是指向 ~/backendContent/.... 一切正常
  • 第二个问题是,当我设置 BundleTable.EnableOptimizations = true;还有更多的问题,深入挖掘我得到了一个巨大的 list
    (4368,1): 运行时错误 CSS1019: 意外 token ,找到“@import”
    (4368,9): 运行时错误 CSS1019: 意外标记,找到 'url("layout.css")'

  • 我不知道这是否重要,但由 @Styles.Render("~/backendcss") 生成的缩小和呈现的样式链接是:
     <link href="/backendcss?v=eMX6YcVB78xPWZV9Dw6seHqsT742J8_M1irfUC0IdaQ1" rel="stylesheet"/>
    

    有任何想法吗?很抱歉,但这是我第一次使用此功能,并且该站点拥有如此多的 css 和 js,它将节省大量带宽并加快整个站点的速度。加上它只是很酷(也就是说,如果我可以让它工作)!!!

    最佳答案

  • ~不应该被渲染。这是asp.net 中的一个特殊字符,意思是the root of the application
  • 我不确定为什么您在实际缩小时遇到问题,但如果没有来源,这将很难诊断。
  • 优化后的链接应该是这样的。最后的 ?v=xxx 用于缓存破坏,以便人们在更改 css 文件时获得更新的 css。
  • 关于asp.net-mvc - 捆绑和缩小没有呈现正确的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17985849/

    相关文章:

    asp.net-mvc - Web部署/发布是否添加了未知的连接字符串?

    .net - mvc windows 身份验证允许域中的所有用户

    c# - 将具体类型转换为嵌套通用基类型

    异步函数调用异步函数的 C# 性能影响

    asp.net-mvc - Azure # 多个站点 - 一次登录(单点登录)

    javascript - 为什么是 "Microsoft JScript runtime error: Object expected"?

    c# - 从模型 MVC 中取消绑定(bind)属性

    c# - 将多个表映射到 Entity Framework 中的单个实体类

    asp.net-mvc-4 - 在 mvc4 中渲染主视图内的部分 View

    asp.net-mvc - 如何判断我的 asp.net mvc View 中是否存在验证错误?