4

I am trying to display an svg image.

When I display the svg image with the below code is does not display.

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

I also tried this syntax, but then it downloads instead of displaying.

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

I have already set the mime type to image/svg+xml in web.config.

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

It appears to be seeing the file type as application/octet-stream even though I have defined it at image/svg+xml. I am running and ASP.NET site with IIS 7.

3 Answers3

0

I recently ran into this problem and my web.config syntax for the mime type looks slightly different to yours.

This:

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

is all I added and it fixed the problem. Hope it helps!

0

Add the following to your web config:

    <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>
Russ
  • 124
  • 1
  • 8
-1

If you have access to .htaccess file (at the root), add this line of code:

AddType image/svg+xml .svg .svgz
Alessio
  • 3,404
  • 19
  • 35
  • 48