简体   繁体   中英

CSS not showing on ASP.Net MVC4 during Visual Studio 2012 Debug

When I debug my site the CSS does not show. I get an Error 500 on the Site.css when I inspect it in Firefox.

My _Layout.cshtml is set to use the css files.

@Styles.Render("~/Content/css")

I did verify the Site.css file is in the correct folder and I can open it directly using Notepad.

I have looked at BundleConfig.cs and I see where it's bundled with the other files.

bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                    "~/Content/themes/base/jquery.ui.core.css",
                    "~/Content/themes/base/jquery.ui.resizable.css",
                    "~/Content/themes/base/jquery.ui.selectable.css",
                    "~/Content/themes/base/jquery.ui.accordion.css",
                    "~/Content/themes/base/jquery.ui.autocomplete.css",
                    "~/Content/themes/base/jquery.ui.button.css",
                    "~/Content/themes/base/jquery.ui.dialog.css",
                    "~/Content/themes/base/jquery.ui.slider.css",
                    "~/Content/themes/base/jquery.ui.tabs.css",
                    "~/Content/themes/base/jquery.ui.datepicker.css",
                    "~/Content/themes/base/jquery.ui.progressbar.css",
                    "~/Content/themes/base/jquery.ui.theme.css"));
    }

the really odd part is I do have this setup on IIS7.5 and the css works, but the background image does not. We are getting error 500 on it also. The IIS_Users does have the rights to access those files.

The last problem is that any images are not showing on the site. On the css the background is set like

background: url("../Images/heroAccent.png") no-repeat;

The Images directory is under the same directory as Views/Models/Controllers etc.

These errors raise for mvc bundling features in css having image path absolute. here are two ways resolved the error

  1. off bundling (using EnableOptimization=false)
  2. Correct image path with doing root path relative

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM