admin管理员组

文章数量:1290394

i am using BundleConfig to bundle my css and javascript files in mvc 4.0 project. just started using it, but somehow my bundled css file get 404 status from the server. wonder what is the problem.

Here is my setting;

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/CSSJSBundles/3rdpartycss").Include(
                    "~/Scripts/jquery.jnotify.css"

)); }

    BundleTable.EnableOptimizations = true;
}

I have created that folder: 'CSSJSBundles' in my root. Do i need to? or it is just virtual folder mvc uses? Also do i need to put any settings in Global.aspx?

I also deleted the folder, still there is 404 error for that bundled css file.

i am using BundleConfig to bundle my css and javascript files in mvc 4.0 project. just started using it, but somehow my bundled css file get 404 status from the server. wonder what is the problem.

Here is my setting;

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/CSSJSBundles/3rdpartycss").Include(
                    "~/Scripts/jquery.jnotify.css"

)); }

    BundleTable.EnableOptimizations = true;
}

I have created that folder: 'CSSJSBundles' in my root. Do i need to? or it is just virtual folder mvc uses? Also do i need to put any settings in Global.aspx?

I also deleted the folder, still there is 404 error for that bundled css file.

Share Improve this question edited Jan 28, 2013 at 5:06 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Jan 28, 2013 at 4:08 HotFrostHotFrost 1,6054 gold badges18 silver badges25 bronze badges 10
  • Please show how you are referencing your bundle and also how the reference renders to the client. – MikeSmithDev Commented Jan 28, 2013 at 4:32
  • Also consider moving your css to a folder called "content". "Scripts" is typically for javascript files. – MikeSmithDev Commented Jan 28, 2013 at 4:48
  • Thanks for the answers all. First, great find on that 'StyleBundle'. I replaced it. Second, it still does not work. Do I have to have such a folder in my project 'CSSJSBundle'? Third, here is how I reference it in my _layout file: @Styles.Render("~/CSSJSBundles/3rdpartycss", "~/CSSJSBundles/widgetscss", "~/CSSJSBundles/controllerscss"); I tried to switch the debug mode to 'off' still does not work.. But isn't that line:'BundleTable.EnableOptimizations = true;' should take care about enabling bundling? Thanks for the help! – HotFrost Commented Jan 28, 2013 at 15:26
  • What happens when you just use @Styles.Render("~/CSSJSBundles/3rdpartycss") – MikeSmithDev Commented Jan 28, 2013 at 15:42
  • 1 @user194033 your global.asax.cs should have BundleConfig.RegisterBundles(BundleTable.Bundles); if you are using MVC4. – MikeSmithDev Commented Jan 28, 2013 at 17:47
 |  Show 5 more ments

2 Answers 2

Reset to default 6
  1. As noted in one of the previous answers, you need to change ScriptBundle to StyleBundle.

  2. BundleTable.EnableOptimizations = true; isn't required. What that does is force bundling and minification to occur when you are in debug mode. The default action is not NOT bundle/minify in debug mode so you can debug more easily. Use that line when you want to see the output as it will happen in release mode.

  3. No you do not need that folder CSSJSBundles to physically exist.

  4. It appears you need to add this line to your Application_Start() in your global.asax.cs file: BundleConfig.RegisterBundles(BundleTable.Bundles);

u have to use StyleBundle ... not a ScriptBundle since it is a css file.

for js files, u should use ScriptBundle.

try

public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new StyleBundle("~/bundles/3rdpartycss").Include(
                        "~/Content/jquery.jnotify.css"
                        ));
        }

:)

本文标签: cBundling css filefile not foundStack Overflow