Skip to content

WASM Deep Linking on IIS Not Working with Default web.config #22227

Open
unoplatform/uno.templates
#2267

Description

@mikernet

Current behavior 🐛

The web.config file created by the template does not define a rewrite rule for deep linking to work, so it doesn't (just results in a 404).

Expected behavior 🎯

There should be a rewrite rule that makes deep linking work.

How to reproduce it (as minimally and precisely as possible) 🔬

No response

Workaround 🛠️

<rules>
  <rule name="SPA fallback - serve app root for client routes" stopProcessing="true">
    <match url=".*" />
    <conditions>
      <!-- Serve existing files and directories as-is -->
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

      <!-- Exclude pre-compressed directories -->
      <add input="{REQUEST_URI}" pattern="^/_compressed_br/" negate="true" />
      <add input="{REQUEST_URI}" pattern="^/_compressed_gz/" negate="true" />
    </conditions>
    <action type="Rewrite" url="/" />
  </rule>
</rules>

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

No response

Uno.Sdk version (and other relevant versions) 📦

No response

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

No response

Activity

  1. added theissue type on Jan 1, 2026
  2. added
    triage/untriaged
    difficulty/tbd
    on Jan 1, 2026
  3. added
    platform/wasm 🌐
    and removed
    triage/untriaged
    difficulty/tbd
    on Jan 9, 2026
  4. MartinZikmund commented on Jan 12, 2026

    @MartinZikmund
    Member

    That is a good find. I think we could include it in the default template for WASM @jeromelaban?

  5. jeromelaban commented on Jan 13, 2026

    @jeromelaban
    Member

    I think so yes, let's include it.

  6. mikernet commented on Jan 29, 2026

    @mikernet
    ContributorAuthor

    The rest of the default web.config doesn't look correct, at least not on NET10 WASM builds. There are no _compressed_br and _compressed_gz folders in the published output.

  7. mikernet commented on Jan 29, 2026

    @mikernet
    ContributorAuthor

    It would probably also be good to set some cache control behavior in there.

  8. mikernet commented on Jan 29, 2026

    @mikernet
    ContributorAuthor

    This is what I am currently using for my web.config. If you want me to PR it or adjust some things let me know. Note that a new RESPONSE_X_COMPRESSION_APPLIED server var is used so that SPA paths like app.com/documents/asdf.br don't get a content-encoding applied to them.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <customErrors mode="Off"/>
      </system.web>
    
      <system.webServer>
        <!-- Disable compression as we're doing it through pre-compressed files -->
        <urlCompression doStaticCompression="false" doDynamicCompression="false" dynamicCompressionBeforeCache="false" />
    
        <rewrite>
          <rules>
            <rule name="Lookup for pre-compressed brotli file" stopProcessing="true">
              <match url="(.*)$"/>
              <conditions>
                <!-- Match brotli requests -->
                <add input="{HTTP_ACCEPT_ENCODING}" pattern="br" />
    
                <!-- Don't rewrite requests that already end with .br -->
                <add input="{REQUEST_URI}" pattern="\.br$" negate="true" />
    
                <!-- Check if the pre-compressed .br file exists on the disk -->
                <add input="{REQUEST_FILENAME}.br" matchType="IsFile" negate="false" />
              </conditions>
              <serverVariables>
                <set name="RESPONSE_X_COMPRESSION_APPLIED" value="br" />
              </serverVariables>
              <action type="Rewrite" url="{R:0}.br" />
            </rule>
    
            <rule name="Lookup for pre-compressed gzip file" stopProcessing="true">
              <match url="(.*)$"/>
              <conditions>
                <!-- Match gzip requests -->
                <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" />
    
                <!-- Don't rewrite requests that already end with .gz -->
                <add input="{REQUEST_URI}" pattern="\.gz$" negate="true" />
    
                <!-- Check if the pre-compressed .gz file exists on the disk -->
                <add input="{REQUEST_FILENAME}.gz" matchType="IsFile" negate="false" />
              </conditions>
              <serverVariables>
                <set name="RESPONSE_X_COMPRESSION_APPLIED" value="gzip" />
              </serverVariables>
              <action type="Rewrite" url="{R:0}.gz" />
            </rule>
    
            <rule name="SPA fallback - serve app root for client routes" stopProcessing="true">
              <match url=".*" />
              <conditions>
                <!-- Serve existing files and directories as-is -->
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <serverVariables>
                <set name="RESPONSE_X_SPA_FALLBACK" value="true" />
              </serverVariables>
              <action type="Rewrite" url="/" />
            </rule>
          </rules>
    
          <outboundRules>
            <rule name="Adjust content encoding for gzip pre-compressed files">
              <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern="" />
              <conditions>
                <add input="{RESPONSE_X_COMPRESSION_APPLIED}" pattern="gzip" />
              </conditions>
              <action type="Rewrite" value="gzip"/>
            </rule>
            
            <rule name="Adjust content encoding for brotli pre-compressed files">
              <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern="" />
              <conditions>
                <add input="{RESPONSE_X_COMPRESSION_APPLIED}" pattern="br" />
              </conditions>
              <action type="Rewrite" value="br"/>
            </rule>
    
            <!-- Cache control: SPA fallback responses must always revalidate -->
            <rule name="Cache control for SPA fallback" stopProcessing="true">
              <match serverVariable="RESPONSE_CACHE_CONTROL" pattern=".*" />
              <conditions>
                <add input="{RESPONSE_X_SPA_FALLBACK}" pattern="true" />
              </conditions>
              <action type="Rewrite" value="no-cache"/>
            </rule>
    
            <!-- Skip additional cache control for non-2xx responses -->
            <rule name="Skip cache control for error responses" stopProcessing="true">
              <match serverVariable="RESPONSE_STATUS" pattern="^[^2]" />
              <action type="None" />
            </rule>
    
            <!-- Cache control: /_framework/dotnet.js is not fingerprinted, must always revalidate -->
            <!-- https://github.com/dotnet/aspnetcore/issues/61425#issuecomment-3815538132 -->
            <rule name="Cache control for dotnet.js" stopProcessing="true">
              <match serverVariable="RESPONSE_CACHE_CONTROL" pattern=".*" />
              <conditions>
                <add input="{REQUEST_URI}" pattern="^/_framework/dotnet\.js(\.br|\.gz)?$" />
              </conditions>
              <action type="Rewrite" value="no-cache"/>
            </rule>
    
            <!-- Cache control: other /_framework files are fingerprinted, can cache forever -->
            <rule name="Cache control for framework files" stopProcessing="true">
              <match serverVariable="RESPONSE_CACHE_CONTROL" pattern=".*" />
              <conditions>
                <add input="{REQUEST_URI}" pattern="^/_framework/" />
              </conditions>
              <action type="Rewrite" value="public, max-age=31536000, immutable"/>
            </rule>
    
            <!-- Cache control: /package_* folders are fingerprinted, can cache forever -->
            <rule name="Cache control for package files" stopProcessing="true">
              <match serverVariable="RESPONSE_CACHE_CONTROL" pattern=".*" />
              <conditions>
                <add input="{REQUEST_URI}" pattern="^/package_" />
              </conditions>
              <action type="Rewrite" value="public, max-age=31536000, immutable"/>
            </rule>
    
            <!-- Cache control: Root SPA entry files must always revalidate -->
            <rule name="Cache control for root files" stopProcessing="true">
              <match serverVariable="RESPONSE_CACHE_CONTROL" pattern=".*" />
              <conditions>
                <add input="{REQUEST_URI}" pattern="^/[^/]*$" />
              </conditions>
              <action type="Rewrite" value="no-cache"/>
            </rule>
          </outboundRules>
        </rewrite>
      </system.webServer>
    </configuration>
  9. mikernet commented on Jan 29, 2026

    @mikernet
    ContributorAuthor

    In your azure static web app config file I see you have a 1 hour max-age set on non-package/TTF files. I can adjust the above to match that before I PR if you prefer that. I just prefer instant updates for visitors and it's only a few files that end up being forced to revalidate on initial load so it's practically inconsequential.

    Isn't the "route": "/*.ttf" redundant? The TTF files should be in the package folder, no?

    Is there a reason you're not marking fingerprinted _framework files as immutable?

  10. jeromelaban commented on Jan 30, 2026

    @jeromelaban
    Member

    Is there a reason you're not marking fingerprinted _framework files as immutable?

    Mainly because this file it's been used less and it got missed in the update of the templates. For the dotnet.json, the latest build of the bootstrapper will also fingerprint that file, so it avoids incorrect reloads on app updates.

    Isn't the "route": "/*.ttf" redundant? The TTF files should be in the package folder, no?

    For this part, I'm not sure why this was added this way. It most likely is a old registration related to versions of uno that weren't supporting fonts as assets. It's supported now, so we should be able to remove this.

    For the file in itself, it's looking good for a PR in uno.templates, but you might want to specify the wasm mime types, so that proper stream loading can happen in browsers (that is unless the IIS environment already provides it).

    Thanks!

  11. mikernet commented on Feb 1, 2026

    @mikernet
    ContributorAuthor

    @jeromelaban

    For the file in itself, it's looking good for a PR in uno.templates, but you might want to specify the wasm mime types

    Ah yeah, I'll leave whatever is in there now for the MIME types. we have those registered at the server level so it wasn't needed.

  12. github-actions commented on Jun 2, 2026

    @github-actions
    Contributor

    This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.

  13. added
    stale
    on Jun 2, 2026
  14. mikernet commented on Jun 2, 2026

    @mikernet
    ContributorAuthor

    Still planning on publishing a PR for this, just have to resolve an issue where this doesn't always work reliably, either because a file that should be fingerprinted doesn't get fingerprinted or something else odd is going on (i.e. with service worker) that causes it to fail loading after a republish. I have a manual workaround I have been using for this but I will investigate later this week before I submit the final PR.

  15. removed
    stale
    on Jun 2, 2026
  16. mikernet commented on Aug 21, 2026

    @mikernet
    ContributorAuthor

    @jeromelaban @MartinZikmund

    Alright, sorry for the delay...pinning down the root cause of the caching issues was a bit painful, but I think I found the problem.

    After publishing a build where only C# or XAML changed, the package_* fingerprint stays the same. That part is actually by design as far as I can tell, since the hash is computed by ShellTask.GeneratePackageFolder() over the static web content only, and managed code lives under _framework with its own fingerprinting. The problem is that returning visitors then end up booting the old version of the app, or a broken mix of old and new, until I force the fingerprint to change (my workaround has been bumping a counter in a file under /Assets just to poke the hash).

    The root cause: uno-config.js lives inside the fingerprinted package_* folder, but it gets rewritten after the fingerprint is computed. The _UnoUpdateDotnetJsFingerprintPublishOutput target (in build/Uno.Wasm.Bootstrap.targets, runs AfterTargets="Publish" when WasmFingerprintDotnetJs is enabled) locates the actual dotnet.<fingerprint>.js produced by that publish and patches package_X/uno-config.js in place to reference it. So when only managed code changes, you get the same folder name with different contents inside it. A returning browser serves its year-old cached copy of package_X/uno-config.js, which points at the previous dotnet.<oldfingerprint>.js, and from there the whole old boot chain loads (or 404s if the old files are gone). The target even deletes the stale .gz/.br copies of uno-config.js after patching, so the file being mutated post-packaging is a known situation, but the cache invariant it breaks doesn't seem to have been considered: a fingerprinted-immutable folder must never contain a file that's written after the fingerprint is computed.

    uno-config.js is effectively a boot manifest whose content depends on the managed/native build output, so it can't live in an immutable cache class keyed off a hash that excludes that output. The cleanest fix seems to be moving it out of the package_* folder to the wwwroot root next to index.html, where the no-cache policy applies. It's a few hundred bytes, so caching it forever has no real value anyway, and this mirrors how the .NET WASM SDK treats its own boot config. There's already a fallback lookup for a root-level uno-config.js in the targets, so some of the plumbing exists. The alternative would be to finalize uno-config.js before the package hash is computed (or re-fingerprint and rename the folder after patching), but that looks messier since the folder name is already baked into the root files by then.

    Let me know if I can PR a fix along with updated web.config fixes.

  17. mikernet commented on Aug 21, 2026

    @mikernet
    ContributorAuthor

    (this bug was also causing problems when locally running WASM tests in the Uno repo, making me go in loops trying to figure out why a bug I fixed still wasn't fixed after I thought I fixed it, until I realized what was going on, lol)

  18. mikernet commented on Sep 21, 2026

    @mikernet
    ContributorAuthor

    The web.config rework is up as unoplatform/uno.templates#2267, and the uno-config.js fingerprint problem described above is now tracked separately in unoplatform/Uno.Wasm.Bootstrap#1076 since the code lives in the bootstrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform/wasm 🌐

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions