Im trying to display .svg files in my web application using Visual Studio 2012, IIS Express v8.0 and ASP .NET Web Forms.
Things i already tried:
<staticContent> <remove fileExtension=".svg" /> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> </staticContent>
<staticContent lockAttributes="isDocFooterFileName"> ... <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> ...
4. Publish the site under IIS, and it's displaying fine. Also, we have a developer using Visual Studio 2013 and it's displaying fine using IIS Express v8.5.
Im adding the .svg as icons, using a span
element with a class that has as background with url of the file, so i can't use this solution: SVG files in VS2012
This is the style of class added to the span:
background: transparent url(images/svg/reports.svg) no-repeat scroll 0px 0px;
What's happening?
Based con @user1429080 suggestion, there's a workaround (altought is not the cleanest way it works):
My workaround for this was to create my own httphandler locally which overwrote the content-type for svg.
public class SvgHandler : IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/svg+xml"; context.Response.BinaryWrite(File.ReadAllBytes(context.Request.PhysicalPath)); context.Response.End(); } }
and in web.config i added:
<httpHandlers> <add verb="*" path="*.svg" type="SvgHandler" /> </httpHandlers>
with this solution you don't have to use IIS express, you can just use the regular development server in visual studio 2010
Source: Visual Studio Not Displaying SVG image as background
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With