Failed to load some css and js in my ASP.NET project with Bundlification
//My BundleConfig.cs look like-
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*",
"~/Scripts/jquery.unobtrusive*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryUI").Include(
"~/Scripts/jquery-ui.js",
"~/Scripts/CustomAutocomplete.js"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js",
"~/Scripts/bootstrap-datetimepicker.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-datetimepicker.css",
"~/Content/site.css",
"~/Content/JqueryUI/jquery-ui.css"));
}
}
//In cshtml file calls like-
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/jqueryval")
When running the project in visual studio, it works fine, but after deploying to server some css and js files don't load correctly I also did IIS settings as described here
after deploying the web page looks like
But the web page should look like this
Please provide a solution ...
source to share
I think the problem is with the setup IIS
. If you are using Windows PC go
Control Panel>All Control Panel Items>Programs and Features
then click on the left side Turn Windows Features on or off
.
then go Internet Information Services>World wide web service>Common HTTP Features
and check Static Content
and click ok
to apply changes.
after this change, restart your computer successfully.
If you are using a Windows server setup, this is all.
How to update your question
After posting, you will miss a few CSS
. You can twist what's missing inspect element
in your browser. and add them in the correct place.
reason: when you add the file somehow, then the file properties ( Build Action
not set to content
)
Solution: So, give the files you are missing and go to visual studio
and right click on that file and go to properties
and install Build Action=content
.
Hope this helps you.
source to share