简体   繁体   中英

CSS Not Working After Published

I got errors ( Not Showing CSS ) in my project after deployed to server, it works fine in local .I found same questions like this and tried them all but still im unable to solved .

what i have tried :

Style bundling not working after IIS deployment (MVC 4)

BundleConfig not rendered after publish in IIS

ASP.NET MVC Bundle not rendering script files on staging server. It works on development server

ASP.NET MVC framework 4.5 CSS bundles does not work on the hosting

Why is my CSS bundling not working with a bin deployed MVC4 app?

Error:

在此处输入图片说明

CSS Shows In Server Like This

<link href="/PMTEST/bundles/font-awesome/css?v=iW7LN24NnEoW62YKSq4wmEVP62Z-QPaYj8Wc4pAfkQA1" rel="stylesheet">
<link href="/PMTEST/bundles/animate/css?v=TS_TayB91ibtNEIEuFyRTY4MKruiSouKnZGvXM9wZzc1" rel="stylesheet">
<link href="/PMTEST/bundles/bootstrap/css?v=fGVgsGSw8MzJqPS1QdcxeRW2yrw4tez5BLZBchwK_HE1" rel="stylesheet">
<link href="/PMTEST/bundles/icon?v=Xt7dqD5fI6gBI3RBoPWSt1nfcmgT1f4bGcYcuT_dBno1" rel="stylesheet">

Bundle Config in my application

 bundles.Add(new StyleBundle("~/bundles/font-awesome/css").Include(
                      "~/Vendor/fontawesome/css/font-awesome.min.css", new CssRewriteUrlTransform()));

In My Layout Page i used Bundle like

   @Styles.Render("~/bundles/font-awesome/css")

Solved , just add

BundleTable.EnableOptimizations = false;

in BoundalConfig

For the fonts part you can use this in your web.config

<system.webServer>
  {...}
 <staticContent>
  <remove fileExtension=".woff" />
  <remove fileExtension=".woff2" />
  <remove fileExtension=".ttf" />
  <mimeMap fileExtension=".ttf" mimeType="application/font-sfnt" />
  <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
  <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>

And for the other bundle make sure the bundle reference path is not an actual file path, because if it is then IIS will handle it as a static file not MVC as a bundle.

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