I have got a website which until recently embedded a png image via aspx in another aspx, the generated html code looks like this:
<div class="widgetcontent" style="padding: 0px; margin: 0px; padding-left: 5px;">
<div id="ctl00_CPHMaster_UPRanges">
<img id="ctl00_CPHMaster_IMRanges" src="range.aspx" style="height:280px;width:460px;border-width:0px;" />
</div>
</div>
range.aspx delivered just an png image that was created on the fly.
I have changed range.aspx now so that it delivers a svg and changed the embedding page so that the resulting html code now looks like this:
<div class="widgetcontent" style="padding: 0px; margin: 0px; padding-left: 5px;">
<div id="ctl00_CPHMaster_UPRanges">
<img id="ctl00_CPHMaster_IMRanges" type="image/svg+xml" src="range.aspx" style="height:280px;width:460px;border-width:0px;" />
</div>
</div>
This does not work right, though. These are the facts:
a) It does work right on my windows developers machine with the ASP.NET development server which is created by VisualStudio 2012.
b) It does work on a test machine which runs IIS 8.5.
c) It does not work on my production machine which runs IIS 7.5.
d) "It does not work" means: The page that should show the embedded svg just shows a broken image sign instead.
e) But when I right-click the broken image sign and select "View image", the svg is shown!
f) When I right click the sole svg and select "view page source", it shows pure svg text, no html around it.
g) Some places in the net write that svg must be enabled in the IIS 7.5 configuration. I did this already. It does still not work.
h) This is not a browser problem, I have checked with Chrome, IE, Firefox and others.
Any help appreciated.
Update 1: Because Brando Zhang asked about the range.aspx code, in principle it looks like this:
<%@ Import Namespace="WVA.Client.Web" %>
<%@ Page Language="c#" AutoEventWireup="true" Culture="en-Us" UICulture="auto" %>
<%@ Import Namespace="WVA.ServiceAccessLayer.WebService" %>
<%@ Import Namespace="WVA.SharedBusinessLogic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>
<head>
<script runat="server" language="C#">
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
byte[] imageByteData = funcGetImage(bildformat);
if (format == Format.Svg)
{
Response.ContentType = "image/svg+xml";
Response.Flush();
string imageTextUtf8 = Encoding.UTF8.GetString(imageByteData, 0, imageByteData.Length);
Response.Write(imageTextUtf8);
}
else if (format == Format.Png)
{
Response.ContentType = "image/png";
Response.Flush();
Response.BinaryWrite(imageByteData);
}
Response.End();
}
</script>
</head>
</html>
Update 2: Because of Hackerman's hint, I tried to add this to the web.config:
<staticContent>
<remove fileExtension=".svg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
This did not make things better for the embedded image. But it had the interesting effect, that afterwards in Chrome and Opera, the "View image in a separate tab" did not any longer show the svg image but the the svg text. Firefox still showed the image.
Update 3: After Lex Li's hint, we've checked with Chrome's developer tool. Could not find any error there. But what is interesting: Where things are ok, the response header contains the line Content-Type: image/svg+xml. With IIS 7.5, where things are not ok, there is no Content-Type: in the response header.