【问题标题】:SVG still not appearing after adding mime type添加 mime 类型后 SVG 仍然没有出现
【发布时间】:2015-07-13 00:40:18
【问题描述】:

我正在尝试显示 svg 图像。

当我使用以下代码显示 svg 图像时,不显示。

<img src="/img/logo.svg" alt="Logo">

我也尝试过这种语法,但它会下载而不是显示。

<embed type="image/svg+xml" src="/img/logo.svg" />

我已经在 web.config 中将 mime 类型设置为 image/svg+xml。

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

尽管我已在 image/svg+xml 中定义了文件类型,但它似乎将文件类型视为 application/octet-stream。我正在使用 IIS 7 运行 ASP.NET 站点。

【问题讨论】:

    标签: asp.net svg iis-7


    【解决方案1】:

    我最近遇到了这个问题,我的 mime 类型的 web.config 语法看起来与你的略有不同。

    这个:

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

    是我添加的所有内容,它解决了问题。希望对您有所帮助!

    【讨论】:

    • 我尝试了您的代码,以便 fileExtension 排除了句点,但这并没有解决问题。
    【解决方案2】:

    将以下内容添加到您的网络配置中:

        <system.webServer>
        <staticContent>
          <remove fileExtension=".svg" />
          <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        </staticContent>
            <handlers>
                <add name="SVG Handler" path="*.svg" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Unspecified" />
            </handlers>
      </system.webServer>
    

    【讨论】:

      【解决方案3】:

      如果您有权访问 .htaccess 文件(在根目录下),请添加以下代码:

      AddType image/svg+xml .svg .svgz
      

      【讨论】:

        猜你喜欢
        • 2013-05-25
        • 1970-01-01
        • 2020-05-25
        • 2012-12-07
        • 2018-10-08
        • 2018-07-09
        • 1970-01-01
        • 1970-01-01
        • 2019-04-21
        相关资源
        最近更新 更多