Svg is not rendered, the browser downloads the file in iis

Asked

Viewed 803 times

2

When accessing the site that contains a svg image, it does not appear but the browser downloads the image and in the debug console appears the following message:

Resource Interpreted as Document but transferred with MIME type application/octet-stream:

the server is from the localweb and is iis, the site is developed in Asp. html is as follows:

<object id="imgSvg" data="map.svg" type="image/svg+xml"></object>

What could be wrong ?!

1 answer

2

Every time IIS receives a request, it retrieves the requested resource (a page, image, etc.) and returns it in the HTTP channel. Imagine that the IIS response is delivered to the browser within an "envelope", and that in the header of that envelope there is a lot of extra information beyond what you asked for. One such information is the type of content inside the envelope.

The browser uses this information to decide how to open the content. If IIS says an image is a page, the browser will try to open it as a page, and vice versa.

What happens in your case is that IIS does not know what SVG is, so it sends as its default type, which is application. This always forces the download.

To resolve, you need to add the SVG type in the IIS MIME type dictionary. Follow the official documentation on how to do this: http://technet.microsoft.com/pt-br/library/cc725608(v=Ws.10). aspx

And in case one day the link breaks:

Open the IIS Manager and navigate to the level you want to manage. (...).

  • Under Feature View, double-click MIME Types.
  • In the Actions panel, click Add.
  • In the Add MIME Type dialog box, type a file name extension in the File Name Extension text box. For example, type . Xyz.
  • Type a mime type in the mime type text box. Type, for example, application/octet-stream.
  • Click OK.

Just replace . Xyz with .svg. And don’t use application/octet-stream, this is what forces downloads. Instead use image/svg+xml.

  • i added using the following syntax: <staticContent> <mimeMap fileExtension=". svg" mimetype="image/svg+xml" /> </staticContent>

  • Without changing the IIS configuration this does not do much good. The browser looks at the HTTP header first. If the header says that your SVG is an application, then the browser will treat it as an application and ignore whatever you have written in the Markup.

  • I made that change in iis :)

  • Ah, it was bad. I’ve never done it this way before and I didn’t even know it was possible (or how to get on a screen that allows it).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.