cmplieger
cmplieger

Reputation: 7361

Enable svg decompression in iis

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!

Upvotes: 2

Views: 1777

Answers (2)

cmplieger
cmplieger

Reputation: 7361

This is now supported in Server 2012.

Upvotes: 0

Andy Davies
Andy Davies

Reputation: 5824

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)

Upvotes: 3

Related Questions