AspCore 404 on production enviroment

Viewed 91

When I create AspCore Hosted Blazor Wasm template project(VS22) and change server's launchSettings.json aspnetcore enviroment to "Production" or delete it entirely, page gets 404. It runs fine on "Development". Am i missing something? Do i need to configure anything else to run the app on production enviroment?

2 Answers

In my case helped adding StaticWebAssetsLoader.UseStaticWebAssets() to Program.cs in BlazorApp.Server.proj:

using Microsoft.AspNetCore.Hosting.StaticWebAssets;
...

var builder = WebApplication.CreateBuilder(args);

StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration);

...

We don't know the content in your launchSettings.json. And I follow your steps to try, and can't reproduce the issue.

So my suggestion is you need upgrade your VS2022 to latest version first.

  1. Then you can create another new sample project to test.
  2. If you not use the latest .net core version, please use .net6. (Same as mine)

My Test Steps:

  1. Delete the environment like below:

    {
    "iisSettings": {
      "windowsAuthentication": false,
     "anonymousAuthentication": true,
     "iisExpress": {
       "applicationUrl": "http://localhost:14136",
       "sslPort": 44320
     }
    },
    "profiles": {
     "BlazorApp1": {
       "commandName": "Project",
       "dotnetRunMessages": true,
       "launchBrowser": true,
       "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
       "applicationUrl": "https://localhost:7060;http://localhost:5060",
       "environmentVariables": {
    
       }
     },
     "IIS Express": {
       "commandName": "IISExpress",
       "launchBrowser": true,
       "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
       "environmentVariables": {
    
       }
     }
    }
    }
    
  2. Run it in VS2022, and it works well.

  3. Publish it, and host in IIS.

    enter image description here

Related