asp.net - 无法在 Visual Studio 2012 (IIS Express) 中显示 .svg 文件

标签 asp.net visual-studio-2012 svg iis-express

我正在尝试使用 Visual Studio 2012、IIS Express v8.0 和 ASP .NET Web 窗体在我的 Web 应用程序中显示 .svg 文件。

我已经尝试过的事情:

  • 将 .svg 扩展名添加到 web.config

  • <staticContent>
      <remove fileExtension=".svg" />
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    </staticContent>
    

  • 将 .svg 扩展名添加到 C:\Users\UserName\Documents\IISExpress\config\applicationhost.config

  • <staticContent lockAttributes="isDocFooterFileName">
      ...
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
      ...
    

  • 将图片的网址复制到浏览器,显示正常。

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

    相关文章:

    c# - .Net Forms 身份验证是否需要 session ?

    javascript - IIS:缺少图像、CSS 和脚本

    c# - WCF 更新服务引用不再为数据协定生成类型

    c# - Windows Phone 8 应用程序出现 "You need to install an app for this task"错误

    javascript - 如何从字符串标记创建 svg 形状(模板)

    c# - 如何增加处理HTTP请求的数量?

    c# - 如何在页面加载时更改按钮 css

    javascript - ASP.Net:RegisterOnSubmitStatement 未调用指定的 javascript 函数

    css - SVG 字母间距也适用于 Mozilla Firefox

    html - 通过符号或 css 包含内联 svg?