5

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:

  1. Adding .svg extension to web.config
<staticContent>
  <remove fileExtension=".svg" />
  <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
  1. Adding .svg extension to C:\Users\UserName\Documents\IISExpress\config\applicationhost.config
<staticContent lockAttributes="isDocFooterFileName">
  ...
  <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
  ...
  1. Copy the URL of the image to the browser, and it's displaying fine.

enter image description here 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?

Community
  • 1
  • 1
DiegoS
  • 816
  • 1
  • 10
  • 26

1 Answers1

1

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

Community
  • 1
  • 1
DiegoS
  • 816
  • 1
  • 10
  • 26