在iis中启用svg解压

发布于 2024-12-10 18:28:25 字数 904 浏览 1 评论 0原文

我尝试在 iis 中启用 SVGZ,但遇到了一些麻烦。这就是我所做的:我向iis控制台添加了一个svgz mime类型,并编译了一个dll来处理解压,我将其添加到“ISAPI Filter”控制台:

namespace svgzHandler
    {
        using System;
        using System.Web;    
        public class svgzHandler : IHttpHandler
        {
            public bool IsReusable { get { return true; } }

            public void ProcessRequest(HttpContext context)
            {
                HttpResponse r = context.Response;
                r.ContentType = "image/svg+xml";
                r.AppendHeader("Content-Encoding", "gzip");
                r.WriteFile(context.Request.PhysicalPath);
            }
        }
    }

但它似乎仍然不起作用...有没有这段代码有错误吗?有什么我忘记的吗?

这是我在浏览器中收到的错误:

This page contains the following errors:

error on line 1 at column 1: Encoding error
Below is a rendering of the page up to the first error.

谢谢您的帮助!

i tried to enable SVGZ in iis but I am running into some trouble. This is what I did: I added a svgz mime type to the iis console and compiled a dll to handle the decompression, that I added to the "ISAPI Filter" console:

namespace svgzHandler
    {
        using System;
        using System.Web;    
        public class svgzHandler : IHttpHandler
        {
            public bool IsReusable { get { return true; } }

            public void ProcessRequest(HttpContext context)
            {
                HttpResponse r = context.Response;
                r.ContentType = "image/svg+xml";
                r.AppendHeader("Content-Encoding", "gzip");
                r.WriteFile(context.Request.PhysicalPath);
            }
        }
    }

But it still does not seem to work... Is there any error in this code? is there anything I forgot?

this is the error I get in the browser:

This page contains the following errors:

error on line 1 at column 1: Encoding error
Below is a rendering of the page up to the first error.

thank you for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

椒妓 2024-12-17 18:28:25

编辑:错过了 SVGZ 位,所以这可能是您真正想要的 - http://forums.iis.net/p/1175276/1970786.aspx

好的,快速提问...

您是否考虑过通过IIS 配置而不是 C#/.net?

在 applicationHost.config 中,您应该看到以下部分

    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </staticTypes>
    </httpCompression>

您可以添加以下内容:

            <add mimeType="image/svg+xml" enabled="true" />

您还需要确保在元素中设置 .svg 的 mimetype

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

(此配置不是从生产服务器复制的,因此不能完全确定这是正确的,但这是我对其他模仿类型所做的)

EDIT: Missed the SVGZ bit so this is what you probably really want - http://forums.iis.net/p/1175276/1970786.aspx

Ok, quick question...

Have you thought about doing this via the IIS config rather than C#/.net?

In the applicationHost.config you should see the following section

    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </staticTypes>
    </httpCompression>

You could add the following:

            <add mimeType="image/svg+xml" enabled="true" />

You'd also need to make sure the mimetype for .svg is set in the element

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

(This config wasn't copied off a production server so no completely sure it's correct but it what I've done for other mimetypes)

你的呼吸 2024-12-17 18:28:25

Server 2012 现在支持此功能。

This is now supported in Server 2012.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文