CSS svg 不适用于本地主机上的 IIS 网络服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12328651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:08:02  来源:igfitidea点击:

svg is not working on IIS webserver on localhost

asp.netcssiissvg

提问by HasanAboShally

I'm trying to set a ".svg" image as background-image using css, but it is not working. The url is valid and returns 200 status code and works on ".png" images.

我正在尝试使用 css 将“.svg”图像设置为背景图像,但它不起作用。url 有效并返回 200 状态代码并适用于“.png”图像。

What is the problem?

问题是什么?

回答by Joachim Isaksson

Your IIS is most likely not configured with SVG as a content type, try adding

您的 IIS 很可能没有配置 SVG 作为内容类型,请尝试添加

<staticContent>
    <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>

inside the <system.webServer>scope of your web.config.

<system.webServer>您的 web.config 范围内。

This will of course only work if your application is the one serving up the svg. If the svgis not contained inside your application but in a separate directory of the web server, you'll need to add the same mapping to your web server instead inside the "mime-types" tab.

这当然只有在您的应用程序是提供svg. 如果svg不包含在您的应用程序中,而是包含在 Web 服务器的单独目录中,您需要将相同的映射添加到您的 Web 服务器,而不是在“mime-types”选项卡中。

回答by Vintesh

Try This - Your App/Website under Default Settings of IIS Manager

试试这个 - 你的应用程序/网站在 IIS 管理器的默认设置下

 Default Site Under IIS Manager

 IIS 管理器下的默认站点

Then "Add" -> { .svg : image/svg+xml }

然后“添加”-> { .svg : image/svg+xml }

回答by Mohammad Farahani

from web.config

来自 web.config

<system.webServer>
    <staticContent>
        <remove fileExtension=".svg" />
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    </staticContent>
</system.webServer>

or in IIS go to MIME Types and add file name extension:.svg MIME Type: image/svg+xml

或在 IIS 中转到 MIME 类型并添加文件扩展名:.svg MIME 类型:image/svg+xml

回答by Markaius

In my case, I included all of the mime-types I wanted in the applicationHost.config file (which is usually located at C:\Windows\System32\inetsrv\config) under the <system.webServer>scope, like Joachim Isakssonmentioned. This allows all of my IIS sites to inherit the same mime-types, and gives you one location to change them if something goes wrong.

在我的例子中,我在 applicationHost.config 文件(通常位于 C:\Windows\System32\inetsrv\config)中包含了我想要的所有 mime 类型<system.webServer>,就像Joachim Isaksson提到的那样。这允许我的所有 IIS 站点继承相同的 MIME 类型,并为您提供一个位置以在出现问题时更改它们。

回答by Kris

Just in case, if anyone want to use IIS Manager for the same, select 'top node' on 'Connections' tree (typically the name of the machine you're on), and on right side, locate 'MIME Types' in 'IIS' section - double click the same. You should see list of all file types with 'Entry Type' as 'Local'. Add '.svg' type as mentioned by posts above (which amends same file as mentioned by 'Markaius'). This enables to 'inherit' same MIME type for any application on the machine.

以防万一,如果有人想使用 IIS 管理器,请在“连接”树上选择“顶级节点”(通常是您所在机器的名称),然后在右侧找到“MIME 类型”中的“ IIS 部分 - 双击相同的部分。您应该看到“条目类型”为“本地”的所有文件类型列表。添加上面帖子中提到的“.svg”类型(修改与“Markaius”提到的相同的文件)。这使得能够为机器上的任何应用程序“继承”相同的 MIME 类型。