IIS Serve pre-compressed dll Brotli files - Blazor Wasm app

Javier Gabrielli 96 Reputation points
2021-10-07T11:08:43.947+00:00

Hello,

I'm devolping an Blazor WASM app that is hosted on IIS ( IIS Version 10.0.19041) 138389-iisversion.png

At time to Publish the Blazor app it generates the pre-compressed files for dll's ( they are compressed in gz and br).
These dll's are stored at the _framework folder:

138475-wwwroot-framework-content.png

Now i want the IIS "serve" this dll.br files correcty, indicating the correct Content-encondig.

To do that i tried to set the web.config, like:

<?xml version="1.0" encoding="UTF-8"?>  
<configuration>  
  <system.webServer>  
    <staticContent>  
		<remove fileExtension=".js" />  
      <remove fileExtension=".blat" />  
      <remove fileExtension=".dat" />  
      <remove fileExtension=".dll" />  
      <remove fileExtension=".json" />  
      <remove fileExtension=".wasm" />  
      <remove fileExtension=".woff" />  
      <remove fileExtension=".woff2" />  
	   <remove fileExtension=".blat.br" />  
      <remove fileExtension=".dat.br" />  
      <remove fileExtension=".dll.br" />  
      <!-- <remove fileExtension=".wasm.br" /> -->  
      <remove fileExtension=".woff.br" />  
      <remove fileExtension=".woff2.br" />  
      <!-- <mimeMap fileExtension=".blat" mimeType="application/octet-stream" /> -->  
      <!-- <mimeMap fileExtension=".dll" mimeType="application/octet-stream" /> -->  
      <!-- <mimeMap fileExtension=".dat" mimeType="application/octet-stream" /> -->  
      <mimeMap fileExtension=".json" mimeType="application/json" />  
      <mimeMap fileExtension=".wasm" mimeType="application/wasm" />  
      <!-- <mimeMap fileExtension=".woff" mimeType="application/font-woff" /> -->  
      <!-- <mimeMap fileExtension=".woff2" mimeType="application/font-woff" /> -->  
	  <mimeMap fileExtension=".js" mimeType="application/javascript" />  
      <!-- <mimeMap fileExtension=".dat.br" mimeType="application/octet-stream" /> -->  
       <mimeMap fileExtension=".dll.br" mimeType="application/octet-stream" />  
      <!-- <mimeMap fileExtension=".json.br" mimeType="application/json" /> -->  
      <!-- <mimeMap fileExtension=".wasm.br" mimeType="application/wasm" /> -->  
      <!-- <mimeMap fileExtension=".blat.br" mimeType="application/octet-stream" /> -->  
      <!-- <mimeMap fileExtension=".html.br" mimeType="text/html" /> -->  
      <!-- <mimeMap fileExtension=".css.br" mimeType="text/css" /> -->  
      <!-- <mimeMap fileExtension=".ico.br" mimeType="image/x-icon" /> -->  
      <!-- <mimeMap fileExtension=".svg.br" mimeType="image/svg+xml" /> -->  
	   <!-- <mimeMap fileExtension=".br" mimeType="application/brotli" /> -->  
    </staticContent>  
    <!-- <httpCompression> -->  
      <!-- <dynamicTypes> -->  
        <!-- <add mimeType="application/octet-stream" enabled="true" /> -->  
        <!-- <add mimeType="application/wasm" enabled="true" /> -->  
      <!-- </dynamicTypes> -->  
    <!-- </httpCompression> -->  
	<!-- <urlCompression doDynamicCompression="false" doStaticCompression="true" dynamicCompressionBeforeCache="false" /> -->  
	<!-- <urlCompression doStaticCompression="true" doDynamicCompression="false" /> -->  
    <!-- <httpCompression sendCacheHeaders="false" /> -->  
	<!-- <httpCompression> -->  
      <!-- <staticTypes> -->  
        <!-- <add mimeType="application/octet-stream" enabled="true" /> -->  
      <!-- </staticTypes> -->  
    <!-- </httpCompression> -->  
    <rewrite>  
	  <outboundRules rewriteBeforeCache="true">  
		<rule name="Add Vary Accept-Encoding"  enabled="true">  
+           <match serverVariable="RESPONSE_Vary" pattern=".*" />  
+           <action type="Rewrite" value="Accept-Encoding" />  
+       </rule>  
        <rule name="Custom br file header" enabled="true">  
          <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern=".*" />  
          <conditions>  
            <add input="{REQUEST_URI}" pattern="\.br$" />  
          </conditions>  
          <action type="Rewrite" value="br"/>  
        </rule>  
      </outboundRules>  
      <rules>  
        <rule name="Serve subdir">  
          <match url=".*" />  
          <action type="Rewrite" url="wwwroot\{R:0}" />  
        </rule>  
		<rule name="Rewrite brotli file" stopProcessing="true">  
          <match url="(.*)"/>  
          <conditions>  
            <add input="{HTTP_ACCEPT_ENCODING}" pattern="br" />  
            <!-- <add input="{REQUEST_FILENAME}" pattern="\.(dat|dll|blat|ico|svg)$" /> -->  
			<add input="{REQUEST_FILENAME}" pattern="\.(dll)$" />  
            <add input="{REQUEST_FILENAME}.br" matchType="IsFile" />  
          </conditions>  
          <action type="Rewrite" url="{R:1}.br" logRewrittenUrl="true" />  
        </rule>  
        <rule name="SPA fallback routing" stopProcessing="true">  
          <match url=".*" />  
          <conditions logicalGrouping="MatchAll">  
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />  
          </conditions>  
           <action type="Rewrite" url="wwwroot\" />  
        </rule>  
      </rules>  
    </rewrite>  
  </system.webServer>  
</configuration>  

But isn't working:

The request:
138429-dllencoding.png
138459-request.png

With error

138476-encoding-error.png

With the "default" web.config

<?xml version="1.0" encoding="UTF-8"?>  
<configuration>  
  <system.webServer>  
    <staticContent>  
      <remove fileExtension=".blat" />  
      <remove fileExtension=".dat" />  
      <remove fileExtension=".dll" />  
      <remove fileExtension=".json" />  
      <remove fileExtension=".wasm" />  
      <remove fileExtension=".woff" />  
      <remove fileExtension=".woff2" />  
      <mimeMap fileExtension=".blat" mimeType="application/octet-stream" />  
      <mimeMap fileExtension=".dll" mimeType="application/octet-stream" />  
      <mimeMap fileExtension=".dat" mimeType="application/octet-stream" />  
      <mimeMap fileExtension=".json" mimeType="application/json" />  
      <mimeMap fileExtension=".wasm" mimeType="application/wasm" />  
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />  
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />  
    </staticContent>  
    <httpCompression>  
      <dynamicTypes>  
        <add mimeType="application/octet-stream" enabled="true" />  
        <add mimeType="application/wasm" enabled="true" />  
      </dynamicTypes>  
    </httpCompression>  
    <rewrite>  
      <rules>  
        <rule name="Serve subdir">  
          <match url=".*" />  
          <action type="Rewrite" url="wwwroot\{R:0}" />  
        </rule>  
        <rule name="SPA fallback routing" stopProcessing="true">  
          <match url=".*" />  
          <conditions logicalGrouping="MatchAll">  
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />  
          </conditions>  
          <action type="Rewrite" url="wwwroot\" />  
        </rule>  
      </rules>  
    </rewrite>  
  </system.webServer>  
</configuration>  

the files are "encoded" and serve as "deflate" and works.

Information:
https://github.com/dotnet/AspNetCore.Docs/issues/20205
https://raw.githubusercontent.com/dotnet/AspNetCore.Docs/master/aspnetcore/blazor/host-and-deploy/webassembly/_samples/web.config
https://stackoverflow.com/questions/48889701/setup-iis10-to-serve-pre-compressed-files

Internet Information Services
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,672 questions
{count} votes

Accepted answer
  1. Javier Gabrielli 96 Reputation points
    2021-10-11T17:59:22.423+00:00

    The default web.config serve the .dll ( without compression) .

    I found the error, the web.config pasted is "correct", at level of application the response was being encoded as deflate. So it was returning the br files( response header set as br encoding) but also encoding that with deflate, so this caused the DECODING error.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.