gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:34:45 25 4
gpt4 key购买 nike

我正在尝试使用 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com