Hosted Blazor wasm App base path works locally, but not as an IIS Sub App

Viewed 543

I have an ASP.NET 4 site and my goal is to create a new hosted blazor web assembly app that runs in a subdirectory of the ASP.NET 4 site running as an application. I've created the blazor app locally and tested it and everything works. I followed all the instructions in the App base path documentation. I even set up the --pathbase command arg, and changed the launch url to app in the launchSettings.json file. It's working well on my local machine from VS 2022 and from a command prompt.

Then I took the existing site in IIS and add a sub app. I updated the app pool to use no managed code. I published the server project within my blazor app and moved it to a directory that is referenced from the IIS sub app. The blazor webassembly runs well. The site loads, but none of the server apps (controllers, api endpoints) work. The source looks like it's referencing app/fetchdata, but the endpoint isn't there. It's returning a 404 error. Also, when you load any of the secondary URLs within the app subdirectory (like app/counter) from the browser url it fails. It works when you navigate from within the app, but not when you link to the page.

Client

wwwroot/index.html

    <base href="/app/" />

launchSettings.json

      "commandName": "Project",
      "commandLineArgs": "--pathbase=/app",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
      "applicationUrl": "https://localhost:7240;http://localhost:5240",
      "launchUrl": "app",

Server

Program.cs

var app = builder.Build();
app.UsePathBase("/app");

launchSettings.json

        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
        "applicationUrl": "https://localhost:7240;http://localhost:5240",
        "launchUrl": "app",
1 Answers

I got it working. It turned out I had a rewrite rule in the ASP.NET 4 root site that was affecting the sub app. Excluding the sub app from the rewrite rule resolved the problem.

Related