Cannot display .svg files in Visual Studio 2012 (IIS Express)

I am trying to display .svg files in my web application using Visual Studio 2012, IIS Express v8.0 and ASP.NET web forms.

Things I've already tried:

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

enter image description here 4. Publish the site under IIS and display it. In addition, we have a developer using Visual Studio 2013, and it perfectly displays the use of IIS Express v8.5.

I add .svg icons as icons using a span element with a class that has a file URL as a background, so I cannot use this solution: SVG files in VS2012

This is the style of the class added to the span:

 background: transparent url(images/svg/reports.svg) no-repeat scroll 0px 0px; 

What's happening?

+5
source share
1 answer

Based on the con @ user1429080 sentence, there is a workaround (altought is not the cleanest way to work it):

My workaround for this was to locally create my own httphandler that overwrite 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 do not need to use IIS express, you can just use a regular development server in visual studio 2010

Source: Visual Studio does not display SVG image as background

+1
source

Source: https://habr.com/ru/post/1261911/


All Articles