我正在尝试使用 Visual Studio 2012、IIS Express v8.0 和 ASP .NET Web 窗体在我的 Web 应用程序中显示 .svg 文件。
我已经尝试过的事情:
<staticContent> <remove fileExtension=".svg" /> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> </staticContent>
<staticContent lockAttributes="isDocFooterFileName"> ... <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> ...
4、在IIS下发布站点,显示正常。此外,我们有一位使用 Visual Studio 2013 的开发人员,并且使用 IIS Express v8.5 显示正常。
我使用
span
添加 .svg 作为图标元素的类以文件的 url 作为背景,所以我不能使用这个解决方案:SVG files in VS2012这是添加到跨度的类的样式:
background: transparent url(images/svg/reports.svg) no-repeat scroll 0px 0px;
发生了什么?
最佳答案
基于 con @user1429080 的建议,有一个解决方法(虽然不是最干净的工作方式):
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
来源:Visual Studio Not Displaying SVG image as background
关于asp.net - 无法在 Visual Studio 2012 (IIS Express) 中显示 .svg 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41332977/