This sample demonstrates how to deploy a Blazor server application developed using ASP.NET core web API to Azure Cloud using Azure App Service.
If you are coming from Chapter 2 then start from Steps to deploy Client app (WebApp-blazor-server).
For code sample from Chapter 3, follow below steps:[TODO]
There are two web projects in this sample. To deploy them to Azure App Service, you'll need, for each one, to:
- create an Azure App Service
- publish the projects to the App Service, and
- update its client(s) to call the web site instead of the local environment.
Please follow the steps in Create Azure App Service and Publish Project with Visual Studio to create App service instances and publish the projects using Visual Studio. Once published, please proceed to the Update the project configuration section
-
Install the VS Code extension Azure App Service.
-
Sign-in to App Service using Azure AD Account.
-
Open the Service project folder.
-
Choose View > Terminal from the main menu.
-
The terminal opens in the Service folder.
-
Run the following command:
dotnet publish --configuration Release
-
Publish folder is created under path
bin/Release/<Enter_Framework_FolderName>
. -
Right Click on Publish folder and select Deploy to Web App.
-
Select Create New Web App, enter unique name for the app, for example ToDoListService-aspnetcore.
-
Select a runtime stack .NET Core 3.1, press Enter.
-
Select Windows as the OS. Press Enter.
Deploy Client app (WebApp-blazor-server or WebApp-calls-API-blazor-server) used in Chapter #2 and #3 both.
-
Open the Client project folder.
-
Choose View > Terminal from the main menu.
-
The terminal opens in the Client folder.
-
Run the following command:
dotnet publish --configuration Release
-
Publish folder is created under path
bin/Release/<Enter_Framework_FolderName>
. -
Right Click on Publish folder and select Deploy to Web App.
-
Select Create New Web App, enter unique name for the app, for example WebApp-blazor-server.
-
Select a runtime stack .NET Core 3.1, press Enter.
-
Select Windows as the OS. Press Enter.
- Go to Azure portal, locate your app service.
- On the Settings tab, select Authentication / Authorization. Make sure
App Service Authentication
is Off. Select Save.
- On the Settings tab, select Authentication / Authorization. Make sure
- Browse your website. If you see the default web page of the project, the publication was successful.
- Navigate back to to the Azure portal. In the left-hand navigation pane, select the Azure Active Directory service, and then select App registrations.
- In the resulting screen, select the
ToDoListService-aspnetcore
application. - From the Branding menu, update the Home page URL, to the address of your service, for example https://ToDoListService-aspnetcore.azurewebsites.net. Save the configuration.
- In your IDE, go to the
Client
project. - Open
Client\appsettings.json
. Only one change is needed - update thetodo:TodoListBaseAddress
key value to be the address of the website you published, for example, https://ToDoListService-aspnetcore.azurewebsites.net. - Publish the project again.
- Run the client! If you are trying multiple different client types (for example, .NET, Windows Store, Android, iOS, Electron etc.) you can have them all call this one published web API.
- Navigate back to to the Azure portal. In the left-hand navigation pane, select the Azure Active Directory service, and then select App registrations.
- In the resulting screen, select the
WebApp-calls-API-blazor-server
application. - From the Branding menu, update the Home page URL, to the address of your service, for example https://WebApp-blazor-server.azurewebsites.net. Save the configuration.
- In the app's registration screen, select Authentication in the menu.
- In the Redirect URIs section, enter the following redirect URIs.
https://WebApp-blazor-server.azurewebsites.net
https://WebApp-blazor-server.azurewebsites.net/signin-oidc
- In the Logout URL section, update the Logout URL fields with the address of your service, for example https://WebApp-blazor-server.azurewebsites.net
- In the Redirect URIs section, enter the following redirect URIs.
⚠️ If your app is using an in-memory storage, Azure App Service will spin down your web site if it is inactive, and any records that your app was keeping will emptied. In addition, if you increase the instance count of your web site, requests will be distributed among the instances. Your app's records, therefore, will not be the same on each instance.
Use Stack Overflow to get support from the community.
Ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before.
Make sure that your questions or comments are tagged with [azure-active-directory
] [msal
] [dotnet
].
If you find a bug in the sample, raise the issue on GitHub Issues.
To provide feedback on or suggest features for Azure Active Directory, visit User Voice page.
If you'd like to contribute to this sample, see CONTRIBUTING.MD.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.