MVC4 - 优化时设置为true捆绑不起作用 [英] MVC4 - Bundling does not work when optimizations are set to true
问题描述
我不知道我没有做正确的位置。我正在使用ASP.NET C#MVC4,我想利用使用新的CSS / JS的优化功能。
I wonder what I don't do correct here. I am using ASP.NET C# MVC4 and I want to take use of new css/js optimization feature.
下面是我的HTML部分
Here is my HTML part
@Styles.Render("~/content/css")
下面是我的 BunduleConfig.cs
部分
bundles.Add(new StyleBundle("~/content/css").Include(
"~/content/css/reset.css",
"~/content/css/bla.css"));
// BundleTable.EnableOptimizations = true;
输出(作品):
<link href="/content/css/reset.css" rel="stylesheet"/>
<link href="/content/css/bla.css" rel="stylesheet"/>
然而,当我取消 BundleTable.EnableOptimizations = TRUE;
HTML输出看起来像这样
However when I uncomment BundleTable.EnableOptimizations = true;
html output looks like this
<link href="/content/css?v=5LoJebKvQJIN-fKjKYCg_ccvmBC_LF91jBasIpwtUcY1" rel="stylesheet"/>
这是的,当然是404我不知道,我做错了什么,请大家帮帮忙,第一次正与MVC4。
And this is, of course is 404. I have no idea where I did something wrong, please help, first time working with MVC4.
推荐答案
我想问题是你把捆在实际存在的一个虚拟的网址,而是一个目录。
I imagine the problem is you putting the bundle at a virtual URL that actually exists, but is a directory.
MVC是从您的包制作一个虚拟文件,并从指定为包洗澡的路径服务不起来。
MVC is making a virtual file from your bundle and serving it up from the path you specify as the bundle bath.
有关这个问题的正确解决方案是使用不直接映射到现有目录的束路径,而是使用该目录内的虚拟文件名(也不会映射到一个真实的文件名)。
The correct solution for that problem is to use a bundle path that does not directly map to an existing directory, and instead uses a virtual file name (that also does not map to a real file name) inside that directory.
例如:
如果您的网站有一个文件夹中名为/内容/ CSS,让你的CSS包如下:
If your site has a folder named /content/css, make your css bundle as follows:
在BundleConfig.cs:
In BundleConfig.cs:
bundles.Add(new StyleBundle("~/content/css/AllMyCss.css").Include(
"~/content/css/reset.css",
"~/content/css/bla.css"));
在页面上:
@Styles.Render("~/content/css/AllMyCss.css")
请注意,这里假设你没有在你的css文件夹命名为AllMyCss.css文件。
Note that this assumes you do NOT have a file named AllMyCss.css in your css folder.
这篇关于MVC4 - 优化时设置为true捆绑不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!