0

I've got a fairly new Asp Net 6.0 with Angular 13. The website works well with Visual Studio 2022, building and launching. We now want to publish the site to Azure App Service. We notice that after publishing with Visual Studio, or with GitHub Actions, we receive a 404 not found response when browsing to the home page. In order to debug this issue, we tried publishing the site locally and then running it:

dotnet publish -c Release

This command runs the "ng build --prod" command as expected and publishes everything to the bin/Release/net6.0/publish/ folder.

The Angular artifacts are all in the bin/Release/net6.0/publish/wwwroot folder, with an index.html file.

Then i run the dotnet assembly.dll command - the site starts:

  • info: Microsoft.Hosting.Lifetime[14] Now listening on: http://localhost:5000
  • info: Microsoft.Hosting.Lifetime[14] Now listening on: https://localhost:5001
  • info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
  • info: Microsoft.Hosting.Lifetime[0] Hosting environment: (null)
  • info: Microsoft.Hosting.Lifetime[0]
  • Content root path: with path

However, I then receive the same 404 error. I've tried looking at the Developer Tools in Chrome, but nothing useful was found.

Does anyone have any idea why this is happening? I've tried amending the address in environment.prod.ts. This doesn't appear to help.

I've reproduced this on a mac and Windows machine.

I imagine the error is because some part of the startup can't be found. But how can I resolve please? thanks

I've put together an example of what i mean here: asp.net 6.0 angular. Please see the readme for instructions

ossentoo
  • 1,675
  • 2
  • 20
  • 44
  • thanks GRD. I don't understand. the dist folder content gets copied by dotnet to bin/Release/net6.0/publish/wwwroot. i don't call ng build --prod directly. the dotnet publish command calls ng build. So what do i have to change? – ossentoo Mar 11 '22 at 11:32
  • https://www.c-sharpcorner.com/article/easily-create-spa-with-net-6-0-and-angular-13-and-deploy-to-azure/ this article will help. – GRD Mar 11 '22 at 11:43
  • https://stackoverflow.com/a/64670634/17427052 here is similiar solution – GRD Mar 11 '22 at 11:46
  • thanks - i'll check it out. – ossentoo Mar 11 '22 at 11:53
  • https://stackoverflow.com/questions/69560100/new-deployed-azure-web-app-is-returning-404-error-code see this also – GRD Mar 11 '22 at 11:54
  • GRD, i've had a look at both the links and neither of them help. The app works when using VS 2022. The particular issue i'm having is only after dotnet publish packages the files that the application doesn't start correctly – ossentoo Mar 11 '22 at 18:44
  • I've added a sample with a readme which describes the issues – ossentoo Mar 11 '22 at 22:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/242874/discussion-between-ossentoo-and-grd). – ossentoo Mar 12 '22 at 07:41

1 Answers1

0

this was a case of the backend url in the index.html being set correctly and also the static files in wwwroot not being served. running dotnet run does not server the static files.

ossentoo
  • 1,675
  • 2
  • 20
  • 44