Rob Bowman
Rob Bowman

Reputation: 8741

Trouble hosting Blazor wasm in Azure App service

I created a blazor wasm app in VS2022 with the option of core hosted. This created 3 projects, client, server and shared.

The server app now contains my web api. I can run the site locally and all works well.

I've created the following Azure DevOps pipeline for build and deployment to an Azure App Service:

trigger:
- master
variables:
  vmImageName: "windows-2022"
stages:
  - stage: Build
    displayName: Build stage
    jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: $(vmImageName)
        steps:
          - task: DotNetCoreCLI@2
            displayName: "build"
            inputs:
              command: build
              projects: "**/BillByTime.sln"
              configuration: "$(buildConfiguration)"
          - task: DotNetCoreCLI@2
            displayName: "test"
            inputs:
              command: test
              projects: "**/BillByTime.UnitTest.csproj"
              arguments: "--configuration Release"
            continueOnError: true
          - task: DotNetCoreCLI@2
            displayName: "publish server app"
            inputs:
              command: publish
              arguments: "--configuration Release --output $(Pipeline.Workspace)/publish_output"
              publishWebProjects: False
              projects: "**/BillByTime.Server.csproj"
              zipAfterPublish: false
          - task: ArchiveFiles@2
            displayName: "Archive files"
            inputs:
              rootFolderOrFile: "$(Pipeline.Workspace)/publish_output"
              includeRootFolder: false
              archiveFile: "$(Pipeline.Workspace)/build$(Build.BuildId).zip"
          - publish: "$(Pipeline.Workspace)/build$(Build.BuildId).zip"
            displayName: "publish zip"
            artifact: "application"
  - stage: DeployDev
    displayName: Deploy Dev Stage
    jobs:
      - deployment: DeployDev
        displayName: deploy dev
        pool:
          vmImage: "Windows-Latest"
        environment: "dev"
        variables:
          - name: env
            value: "dev"
          - name: svcConnection
            value: "BizTalkersSvcCon"
        strategy:
          runOnce:
            deploy:
              steps:
                - download: current
                  artifact: application
                - download: current
                  artifact: sql-script
                - task: AzureWebApp@1
                  displayName: deploy blazor app
                  inputs:
                    azureSubscription: ${{variables.svcConnection}}
                    appType: "webAppLinux"
                    appName: appsvc-billbytime-webapi-${{variables.env}}-001
                    package: $(Pipeline.Workspace)/application/**/*.zip
                    deployToSlotOrASE: false
                    resourceGroupName: rg-BillByTime-${{variables.env}}-001

The pipeline runs without error. If I navigate to the url of the app service (https://appsvc-billbytime-webapi-dev-001.azurewebsites.net) I get a 403 Forbidden error.

By making an FTP connection to the App Service, I can see the folder structure and files that have been deployed:

folders

Within /site/wwwroot/BillByTime.Server/wwwroot I see the blazor client app is also deployed.

client-app

So, it seems all the files have deployed ok but I seem to be missing some kind of config that would route the browser to /site/wwwroot/BillByTime.Server/wwwroot/index.html ?

Upvotes: 1

Views: 624

Answers (1)

Jason Pan
Jason Pan

Reputation: 22082

Please copy the all the contents under BillByTime.Server and paste to /site/wwwroot.

The reason for this problem is that after the release of the wwwroot folder, there is an extra layer of BillByTime.Server. Normally, under wwwroot, a web.config file is required.

Or you also can change the wwwroot like below:

enter image description here

Upvotes: 1

Related Questions