Visual Studio does not display SVG image as background

I have an asp.net project with an html file (Html ​​5). I am trying to set SVG as the background of my body tag using CSS 3. I have a file like this.

enter image description here

In my Style.css.

enter image description here

when i double click and open the html file. I can see the body filled with SVG, but this does not work when I debug VS VS.

This is what I got when I debug html using vs 2010.

enter image description here

Did I miss something? How to fix it?

+3
source share
2 answers

Visual Studio's embedded web server has a limited set of mime types that it can serve. SVG is not one of them.

See here for a brief answer: https://serverfault.com/questions/359904/how-to-configure-iis-for-svg-and-web-testing-with-visual-studio

+5
source

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

+6
source

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


All Articles