Now, let’s see how we can deploy our application to App Service.
Automated deployment Automated deployment, or continuous integration, is a process used to push out new features and bug fixes in a fast and repetitive pattern with minimal impact on end users.
Azure supports automated deployment directly from several sources. The following options are available:
Azure Repos: You can push your code to Azure Repos, build your code in the cloud, run the tests, generate a release from the code, and finally push your code to an Azure Web App. GitHub: Azure supports automated deployment directly from GitHub. When you connect your GitHub repository to Azure for automated deployment, any changes you push to your production branch on GitHub are automatically deployed for you. Bitbucket: Due to its similarities to GitHub, you can configure an automated deployment with Bitbucket.
In this unit, you learn how to create an Azure App Service web app using the Azure portal.
Why use the Azure portal?
The first step in hosting your web application is to create a web app (an Azure App Service app) inside your Azure subscription.
There are several ways you can create a web app. You can use the Azure portal, the Azure Command Line Interface (CLI), a script, or an integrated development environment (IDE) like Visual Studio.
The information in this unit discusses how to use the Azure portal to create a web app, and you use this information to create a web app in the next exercise. For this module, we demonstrate using the Azure portal because it’s a graphical experience, which makes it a great learning tool. The portal helps you discover available features, add other resources, and customize existing resources.
What is Azure App Service?
Azure App Service is a fully managed web application hosting platform. This platform as a service (PaaS) offered by Azure allows you to focus on designing and building your app while Azure takes care of the infrastructure to run and scale your applications.
Deployment slots
Using the Azure portal, you can easily add deployment slots to an App Service web app. For instance, you can create a staging deployment slot where you can push your code to test on Azure. Once you’re happy with your code, you can easily swap the staging deployment slot with the production slot. All it takes is a few mouse clicks in the Azure portal.
Continuous integration/deployment support
The Azure portal provides out-of-the-box continuous integration and deployment with Azure Repos, GitHub, Bitbucket, FTP, or a local Git repository on your development machine. You can connect your web app with any of the preceding sources, and App Service does the rest for you. It automatically syncs your code and any future changes on the code into the web app. Furthermore, with Azure Repos, you can define your own build and release process. A full process that compiles your source code, runs the tests, builds a release, and finally deploys the release into your web app every time you commit the code. All that happens implicitly, without any need for you to intervene.
Integrated Visual Studio publishing and FTP publishing
In addition to being able to set up continuous integration/deployment for your web app, you can always benefit from the tight integration with Visual Studio to publish your web app to Azure via Web Deploy technology. App Service also supports FTP-based publishing for more traditional workflows.
Built-in autoscale support (automatic scale-out based on real-world load)
The ability to scale up/down or scale out is baked into the web app. Depending on the web app’s usage, you can scale your app up/down by increasing/decreasing the resources of the underlying machine that’s hosting your web app. Resources can be the number of cores or the amount of RAM available. On the other hand, you can scale out your app by increasing the number of machine instances that are running your web app.In this unit, you learn how to create an Azure App Service web app using the Azure portal.
Why use the Azure portal?
The first step in hosting your web application is to create a web app (an Azure App Service app) inside your Azure subscription.
There are several ways you can create a web app. You can use the Azure portal, the Azure Command Line Interface (CLI), a script, or an integrated development environment (IDE) like Visual Studio.
The information in this unit discusses how to use the Azure portal to create a web app, and you use this information to create a web app in the next exercise. For this module, we demonstrate using the Azure portal because it’s a graphical experience, which makes it a great learning tool. The portal helps you discover available features, add other resources, and customize existing resources.
What is Azure App Service?
Azure App Service is a fully managed web application hosting platform. This platform as a service (PaaS) offered by Azure allows you to focus on designing and building your app while Azure takes care of the infrastructure to run and scale your applications.
Deployment slots
Using the Azure portal, you can easily add deployment slots to an App Service web app. For instance, you can create a staging deployment slot where you can push your code to test on Azure. Once you’re happy with your code, you can easily swap the staging deployment slot with the production slot. All it takes is a few mouse clicks in the Azure portal.
Continuous integration/deployment support
The Azure portal provides out-of-the-box continuous integration and deployment with Azure Repos, GitHub, Bitbucket, FTP, or a local Git repository on your development machine. You can connect your web app with any of the preceding sources, and App Service does the rest for you. It automatically syncs your code and any future changes on the code into the web app. Furthermore, with Azure Repos, you can define your own build and release process. A full process that compiles your source code, runs the tests, builds a release, and finally deploys the release into your web app every time you commit the code. All that happens implicitly, without any need for you to intervene.
Integrated Visual Studio publishing and FTP publishing
In addition to being able to set up continuous integration/deployment for your web app, you can always benefit from the tight integration with Visual Studio to publish your web app to Azure via Web Deploy technology. App Service also supports FTP-based publishing for more traditional workflows.
Built-in autoscale support (automatic scale-out based on real-world load)
The ability to scale up/down or scale out is baked into the web app. Depending on the web app’s usage, you can scale your app up/down by increasing/decreasing the resources of the underlying machine that’s hosting your web app. Resources can be the number of cores or the amount of RAM available. On the other hand, you can scale out your app by increasing the number of machine instances that are running your web app.
Imagine you’re an employee of a pizza company named Contoso Pizza. Your team maintains an internal application that’s written in ASP.NET MVC 5 and running on .NET Framework 4.8. Your manager has asked you to evaluate whether you should upgrade the application to ASP.NET Core.
We discussed screen readers briefly in the “Accessibility and screen readers” unit. A screen reader does what the name implies: it reads the screen to you. Plus, it provides audible cues, context, and control to move through and interact with web applications and complex content.
Your users have various visual abilities. Someone who is color-blind might not be able to differentiate between colors or might have difficulty working with colors that are similar to one another. Other users might use zoom to enlarge content. Accommodating various visual abilities is an important part of accessibility.
Contrast
Ensuring adequate contrast makes it easier for everyone to read text content, interpret graphical elements, identify UI components, and notice when those components change state. People with low vision often have difficulty reading text, identifying buttons that don’t contrast with the background, or determining the state of UI components. The problems can be exacerbated if a person has a color deficiency that lowers the perceived contrast even further.
Fortunately, contrast ratios can be checked programmatically. You can use the FastPass tool in Accessibility Insights for Web to perform contrast checking.
One of the most important ways that users interact with web applications is by using forms to submit information. There are several important considerations in how you write your forms to make sure all of your users can move through, fill in, and submit them.
The fundamental concept is to use HTML the way it was designed. Standard HTML form elements are built for accessibility, but it’s easy to unconsciously override accessibility features with the latest JavaScript library or overly clever CSS.
Labels
Every input tag on your forms should have an associated <label> tag to identify it. This tag is different from just putting some text on the screen next to the input element, because labels are programmatically associated with the input elements. For example, screen readers read the label text when the input element has focus.
Selecting a label activates the input and makes interaction easier. It also helps users with touchscreen devices. Instead of looking for a tiny checkbox on a phone, users can just select the label.
Here’s an example of an input text field with an associated label:
Let’s start with the simplest case: required fields. Rather than indicating these fields by using color coding or other custom UI elements, you can use the required attribute on the HTML input element. Screen readers can handle this attribute, and users on any browser see the required field interaction by using the standard UI for their platform.
HTMLCopy
<input type="text" id="name" required>
If you want to include more visual design for required elements, you can use the CSS pseudo-selector. It’s fine to provide other styling, but using the required attribute provides accessible indication to all users. The following CSS style sets the border color for required text boxes to red:
cssCopy
input:required
{
border-color: red;
}
Input types
HTML form elements offer comprehensive validation support for common input types. Rather than using custom JavaScript and HTML to show a date picker, for instance, you can just use this code:
HTMLCopy
<input type="date" id="birthday">
This code provides a native date picker pop-up for the user’s browser and operating system. The date picker is tested for accessibility and it handles validation for you. There’s broad support for input types that used to require custom Regex validation, UI elements, and JavaScript:
Email
Date
Month
Week
Time
Range
URL
Color
So now you can write less code and it’s more accessible. It’s a win-win!
Tab order
Users who move through your form by using a keyboard or screen reader rely on tab order. It works unless you have a complicated form design or are trying to do something too fancy. It’s hard to mess up tab order for most forms. However, it’s an important feature to test.
You can test tab order by selecting the Tab key on your keyboard and checking the interaction. However, as we see in the next exercise, Accessibility Insights for Web can make this testing a lot easier.
One of the most important ways that users interact with web applications is by using forms to submit information. There are several important considerations in how you write your forms to make sure all of your users can move through, fill in, and submit them.
The fundamental concept is to use HTML the way it was designed. Standard HTML form elements are built for accessibility, but it’s easy to unconsciously override accessibility features with the latest JavaScript library or overly clever CSS.
Labels
Every input tag on your forms should have an associated <label> tag to identify it. This tag is different from just putting some text on the screen next to the input element, because labels are programmatically associated with the input elements. For example, screen readers read the label text when the input element has focus.
Selecting a label activates the input and makes interaction easier. It also helps users with touchscreen devices. Instead of looking for a tiny checkbox on a phone, users can just select the label.
Here’s an example of an input text field with an associated label:
Let’s start with the simplest case: required fields. Rather than indicating these fields by using color coding or other custom UI elements, you can use the required attribute on the HTML input element. Screen readers can handle this attribute, and users on any browser see the required field interaction by using the standard UI for their platform.
HTMLCopy
<input type="text" id="name" required>
If you want to include more visual design for required elements, you can use the CSS pseudo-selector. It’s fine to provide other styling, but using the required attribute provides accessible indication to all users. The following CSS style sets the border color for required text boxes to red:
cssCopy
input:required
{
border-color: red;
}
Input types
HTML form elements offer comprehensive validation support for common input types. Rather than using custom JavaScript and HTML to show a date picker, for instance, you can just use this code:
The web is an amazing place, and it’s best when everyone can participate. The first step in building accessible web applications is a basic awareness of the diverse ways that users interact with those applications.
The importance of inclusive design
When you’re developing a web app, it’s easy to get into a workflow of writing some code, testing it in a browser, fixing bugs, repeat, repeat, repeat. Unfortunately, this approach leads to web apps that don’t work for everyone.
There are good reasons to consider accessibility in your web apps:
A substantial number of your potential users might have one or more impairments that require them to interact differently with web apps. Improving accessibility increases your potential user base.
Web apps are now under many legal requirements for compliance with web accessibility standards. Failure to incorporate accessibility into your development methodology can result in legal and financial penalties.
Accessibility is a human right. Helping others to gain full access to the internet is the ethical thing to do.
We don’t all browse the same way
Web developers often focus on conventional browser-based interaction, but many users access applications in different ways.
Screen readers
One of the best-known accessibility tools is a screen reader. Screen readers are commonly used clients for people with vision impairments. They’re built into most operating systems.
At its most basic, a screen reader reads a page from top to bottom audibly. If your page is all text, the reader conveys the information in a similar way to a browser. It’s rare that webpages are purely text; they contain links, graphics, color, and other visual components. Care must be taken to ensure that a screen reader can correctly read this information.
Visual impairments
Visual ability is a spectrum. Some users require, or prefer, an auditory experience. Many prefer a visual experience but might encounter issues with small text or contrast.
Input devices
Developers commonly consider keyboard, mouse, and mobile touchscreen interactions in web apps. However, these devices are just some of the ways that users interact with computers and web apps. Other modes include ergonomic keyboards, chording keyboards, voice interaction, eye tracking, and head tracking.
The web is an accessible platform
All this information might seem a little daunting. Fortunately, HTML and web standards are designed for accessibility. In many cases, when you follow web standards, your web apps “just work” in various accessibility scenarios or require minor modification.
Before you can automate your website deployments, you need to deploy the existing eShop app manually to Azure Kubernetes Service (AKS). You create the Azure resources and deploy the app to AKS using Azure CLI commands and bash scripts. Finally, you create an Azure Active Directory (Azure AD) service principal to allow GitHub Actions to deploy to AKS and Azure Container Registry.
In a form, you should provide instructions to the website user on how to complete each value properly, but you should also check the values that they enter. Blazor provides simple tools that can perform this validation with the minimum of custom code.
In this unit, you learn how to annotate models so that Blazor knows what data to expect. You also learn how to configure a form so it validates and responds to user data correctly.
Validate user input in Blazor forms
When you collect information from a website user, it’s important to check that it makes sense and is in the right form:
For business reasons: Customer information such as a telephone number or order details must be correct to give good service to users. For example, if your webpage can spot a malformed telephone number as soon as the user enters it, you can prevent costly delays later.
For technical reasons: If your code uses form input for calculations or other processing, incorrect input can cause errors and exceptions.
For security reasons: Malicious users might try to inject code by exploiting input fields that aren’t checked.
Website users are familiar with validation rules that check for the presence and correct format of the details they enter. Required fields are often marked with an asterisk or a Required label. If they omit a value or enter a poorly formatted value, they see a validation message instructing them on how to correct the problem. The validation message might appear when the user tabs out of a field or when they select the Submit button.
Here’s an example form where the user submits invalid data. In this case, there are validation messages at the bottom of the form and invalid fields are highlighted in red. You’ll build this form in the next exercise:
It’s a good idea to make validation messages as helpful as possible. Don’t assume any knowledge from the user; for example, not everyone knows the format of a valid email address.
When you use the EditForm component in Blazor, you have versatile validation options available without writing complex code:
In your model, you can use data annotations against each property to tell Blazor when values are required and what format they should be in.
Within your EditForm component, add the DataAnnotationsValidator component, which checks the model annotations against the user’s entered values.
Use the ValidationSummary component when you want to display a summary of all the validation messages in a submitted form.
Use the ValidationMessage component when you want to display the validation message for a specific model property.
Prepare models for validation
Start by telling the DataAnnotationsValidator component what valid data looks like. You declare validation restrictions by using annotation attributes in your data model. Consider this example:
C#Copy
using System.ComponentModel.DataAnnotations;
public class Pizza
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string Description { get; set; }
[EmailAddress]
public string ChefEmail { get; set;}
[Required]
[Range(10.00, 25.00)]
public decimal Price { get; set; }
}
We use this model in a form that enables Blazing Pizza personnel to add new pizzas to the menu. It includes the [Required] attribute to ensure that the Name and Price values are always completed. It also uses the [Range] attribute to check that the price entered is within a sensible range for a pizza. Finally, it uses the [EmailAddress] attribute to check the ChefEmail value entered is a valid email address.