Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Deploy a Blazor app on Azure Static Web Apps

Feedback

In this article

Azure Static Web Apps publishes a website to a production environment by building apps from a GitHub repository supported by a serverless backend. The following tutorial shows how to deploy C# Blazor WebAssembly app that displays weather data returned by a serverless API.

Note

For steps to deploy a Blazor app via Visual Studio, seeDeploy a Blazor app on Azure Static Web Apps.

Prerequisites

1. Create a repository

This article uses a GitHub template repository to make it easy for you to get started. The template features a starter app that you can deploy to Azure Static Web Apps.

  1. Make sure you're signed in to GitHub and go to the following location to create a new repository:https://github.com/staticwebdev/blazor-starter/generate
  2. Name your repositorymy-first-static-blazor-app.

2. Create a static web app

Now that the repository is created, create a static web app from the Azure portal.

  1. Go to theAzure portal.

  2. SelectCreate a Resource.

  3. Search forStatic Web Apps.

  4. SelectStatic Web App.

  5. SelectCreate.

  6. On theBasics tab, enter the following values.

    PropertyValue
    SubscriptionYour Azure subscription name.
    Resource groupmy-blazor-group
    Namemy-first-static-blazor-app
    Plan typeFree
    Region for Azure Functions API and staging environmentsSelect a region closest to you.
    SourceGitHub
  7. SelectSign in with GitHub and authenticate with GitHub, if you're prompted.

  8. Enter the following GitHub values.

    PropertyValue
    OrganizationSelect your desired GitHub organization.
    RepositorySelectmy-first-static-blazor-app.
    BranchSelectmain.

    Note

    If you don't see any repositories, you may need to authorize Azure Static Web Apps on GitHub. Then browse to your GitHub repository and go toSettings > Applications > Authorized OAuth Apps, selectAzure Static Web Apps, and then selectGrant. For organization repositories, you must be an owner of the organization to grant the permissions.

  9. In theBuild Details section, selectBlazor from theBuild Presets drop-down and the following values are populated.

    PropertyValueDescription
    App locationClientFolder containing the Blazor WebAssembly app
    API locationApiFolder containing the Azure Functions app
    Output locationwwwrootFolder in the build output containing the published Blazor WebAssembly application
  10. SelectReview + Create to verify the details are all correct.

  11. SelectCreate to start the creation of the static web app and provision a GitHub Actions for deployment.

  12. Once the deployment is completed, selectGo to resource.

  13. SelectGo to resource.

Go to resource button

3. View the website

There are two aspects to deploying a static app. The first provisions the underlying Azure resources that make up your app. The second is a GitHub Actions workflow that builds and publishes your application.

Before you can go to your new static web app, the deployment build must first finish running.

The Static Web Apps overview window displays a series of links that help you interact with your web app.

  1. Select the banner that says,Click here to check the status of your GitHub Actions runs to see the GitHub Actions running against your repository. Once you verify the deployment job is complete, then you can go to your website via the generated URL.

    Screenshot showing overview window.

  2. Once GitHub Actions workflow is complete, you can select theURL link to open the website in new tab.

    Screenshot of Static Web Apps Blazor webpage.

4. Understand the application overview

Together, the following projects make up the parts required to create a Blazor WebAssembly application running in the browser supported by an Azure Functions API backend.

Visual Studio projectDescription
ApiThe C# Azure Functions application implements the API endpoint that provides weather information to the Blazor WebAssembly app. TheWeatherForecastFunction returns an array ofWeatherForecast objects.
ClientThe front-end Blazor WebAssembly project. Afallback route is implemented to ensure client-side routing is functional.
SharedHolds common classes referenced by both the Api and Client projects, which allow data to flow from API endpoint to the front-end web app. TheWeatherForecast class is shared among both apps.

Blazor static web appComplete Blazor app.

Fallback route

The app exposes URLs like/counter and/fetchdata, which map to specific routes of the app. Since this app is implemented as a single page, each route is served theindex.html file. To ensure that requests for any path returnindex.html, afallback route gets implemented in thestaticwebapp.config.json file found in the client project's root folder.

{  "navigationFallback": {    "rewrite": "/index.html"  }}

The JSON configuration ensures that requests to any route in the app return theindex.html page.

Clean up resources

If you're not going to use this application, you can delete the Azure Static Web Apps instance through the following steps:

  1. Open theAzure portal.
  2. Search formy-blazor-group from the top search bar.
  3. Select on the group name.
  4. SelectDelete.
  5. SelectYes to confirm the delete action.

Next steps

Related articles


Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?