Bootstrap Icons not showing in published ASP.NET M

2019-03-08 08:34发布

--- NB: Go to the EDITED 2 section for summary ----

I have an ASP.NT MVC (4) application. I integrated (twitter)Bootstrap to it. Bootstrap is working perfectly, but the icons does not show correctly when I publish the application.

I tried to republish the application without success.

For clarify I put some images here below.

When I run my application from VS2013 the result is this (which is OK):

Local Icons

In booth, IE and Chrome.

But when I run the published application the result is this (which is NOT ok):

  • Chrome

Published Chrome

  • IE (10)

Published IE

This problem has, somehow, to be with the evaluated CSS but I don't know at which point this could be happening.

The evaluated css in the local application are this (which is OK):

  • Chrome

Local CSS Chrome

  • IE

Local CSS IE

But In the published application I have this (which is NOT ok):

  • Chrome:

Published CSS Chrome

  • IE:

Publisehd CSS IE

Some has experienced this behavior?

What can I do for solve this weird problem?

--------------------------- EDITED ------------------------------

I get the font files (.eot, .svg, .ttf and .woff) to be included when publishing my application. When I access the default page (application root http://localhost/) which is the page showing the icons the files being showed in the Chrome's Developper Tools Network tab are:

Network Tab

Before including the files I was getting 404 errors for the files, so I could guess they continue to be requested even if they are not showed in the Network Tab.

Though, the icons are not showed correctly.

------------------------ EDITED 2 ---------------------------

Well, I restart my site in the IIS 7. And the request start to be triggered. These are the file requests showed in the Chrome's Developper Tools Network Tab:

New Requested files

The resquest is then looking for the files in: /Content/themes/fonts/ but they are in: /Content/themes/base/fonts/

The base folder containt a bootstrap folder which containt the bootstrap.css file. In the CSS file there are this class referening the fonts files:

@font-face {
  font-family: 'Glyphicons Halflings';
  src: url('../fonts/glyphicons-halflings-regular.eot');
  src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');
}

It seems the references to the fonts files are good as the the files tree is this:

files tree

I could change the class to be:

@font-face {
      font-family: 'Glyphicons Halflings';
      src: url('../base/fonts/glyphicons-halflings-regular.eot');
      src: url('../base/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../base/fonts/glyphicons-halflings-regular.woff') format('woff'), url('../base/fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../base/fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');
    }

But, I would actually know what this is happening and how to solve it! Besides, the icons will be showed in the published site but not in the local site (running from VS2013 with iisexpress). Thank you in advance for your help!

17条回答
在下西门庆
2楼-- · 2019-03-08 08:42

You have to set the property Copy to Output Directory of the files on Copy always

查看更多
看我几分像从前
3楼-- · 2019-03-08 08:43

I had this problem too. Rather than have to move files around you can create a virtual directory in the root of the project in IIS.

查看更多
虎瘦雄心在
4楼-- · 2019-03-08 08:45

Anyone still looking for an alternate answer, this method suggested on another StackOverflow answer resolves the issue.

Change the Build action on the .eot, .ttf, & .woff files to "Content" instead of the default value of "None". Doing this solved my issue.

查看更多
女痞
5楼-- · 2019-03-08 08:46

Try disabling bundle optimizations, what happens is that the path to the bundled css stylesheet conflicts with referenced images. For example. You might have a css file /Content/css/style.css => in a bundle "~/Content/css" in which an image is specified as such

    .someclass { background-image:url(img/someimg.png) }

This would resolve the image to /Content/css/img/someimg.png

Now you deploy the release build and the css file is now rendered to a bundle URL such as /Content/css Now the image URL resolves to /Content/img/someimg.png

You can change this behaviour in App_Start\BundleConfig.cs

    System.Web.Optimization.BundleTable.EnableOptimizations = false;
查看更多
叼着烟拽天下
6楼-- · 2019-03-08 08:49

try <link rel="stylesheet" href="~/Content/bootstrap/bootstrap.css" /> and try @Styles.Render("~/bootstrap/css") The only difference that I found

查看更多
Lonely孤独者°
7楼-- · 2019-03-08 08:56

Run Fiddler or use the network tab on your browser's developer tools. What you should look for is 404 results for the requests that download the font files.

Also make sure that the published site contains ~/Fonts/glyphicons-halflings-regular.[eot,svg,ttf,woff] files.

The differences you are seeing in the computed CSS rules are because of minified CSS files (controlled by debug=true/false setting in web.config file). The value \e013 is just another way of writing the symbol you are seeing.

查看更多
登录 后发表回答