9

我在将 SVG 文件设置为 MVC 3 站点(Razor 视图引擎)中元素的背景时遇到了一些问题,并且想知道 ASP.Net 开发服务器(Cassini?)是否正确地为 SVG 文件提供服务。

我的 SVG 文件位于,/img/plus.svg这是它的内容

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="25px" height="25px" viewBox="0 0 25 25" enable-background="new 0 0 25 25" xml:space="preserve">
<polygon fill="#231F20" points="25,8.621 16.38,8.621 16.38,0 8.621,0 8.621,8.621 0,8.621 0,16.379 8.621,16.379 8.621,25 
    16.38,25 16.38,16.379 25,16.379 "/>
</svg>

我用来设置背景的 css 规则是这样的:

.plusIcon { background-image: url(@Url.Content("~/img/plus.svg")); }

我还将它添加到我的 Web.Config<system.webServer><staticContent>部分:

<!-- Proper svg serving. Required for svg webfonts on iPad -->
<remove fileExtension=".svg"/>
<remove fileExtension=".svgz"/>
<mimeMap fileExtension=".svg" mimeType="images/svg+xml" />
<mimeMap fileExtension=".svgz" mimeType="images/svg+xml" />

当我导航到网址/img/plus.svg时,文件已正确下载。

这只是一个开发服务器问题,我应该在 IIS 中尝试吗?

4

1 回答 1

11

原来这只是 Cassini、ASP.Net 开发服务器的问题。当上传到适当的 IIS 站点时,SVG 文件会被正确地提供

于 2011-05-13T16:19:31.343 回答