Output encoding using UrlEncoder
URL encoding converts characters in the output into ASCII format. It also replaces unsafe characters with a %
character as a prefix and then adds two hexadecimal digits.
Here's a partial list of characters and their URL-encoded equivalents:

Table 1.2 – Percent encoded characters and their equivalents
In this recipe, you will learn how to use UrlEncoder
to escape URLs.
Getting ready
Using Visual Studio Code, open the sample Online Banking app folder at \Chapter01\output-encoding-url\before\OnlineBankingApp
.
How to do it…
Let's take a look at the steps for this recipe:
- Launch Visual Studio Code and open the starting exercise folder by typing the following command:
code .
- Open the
Pages\FundTransfers\Index.cshtml
file and add an@inject
directive to the Razor page to inject theUrlEncoder
service:@inject System.Text.Encodings.Web.UrlEncoder urlEncoder
- Replace the markup...