The source code:
@{ ViewBag.Title = "سلام علیک"; }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>@ViewBag.Title</title>
</head>
<body>
<div class="container" dir="rtl">
@RenderBody()
</div>
</body>
</html>
It's well rendered in browser but I want the same text in html source (for some search engine optimizer software)
And the output:
<!DOCTYPE html>
<html>
<head>
<title>سلام علیک</title>
</head>
<body>
...
</body>
</html>
Because, by default, the HTML encoding engine will only safelist the basic latin alphabet (because browsers have bugs. So we're trying to protect against unknown problems). The &XXX values you see still render as correctly as you can see in your screen shots, so there's no real harm, aside from the increased page size.
If the increased page size bothers you then you can customise the encoder to safe list your own character pages (not language, Unicode doesn't think in terms on language)
To widen the characters treated as safe by the encoder you would insert the following line into the ConfigureServices() method in startup.cs;
services.AddSingleton<HtmlEncoder>(
HtmlEncoder.Create(allowedRanges: new[] { UnicodeRanges.BasicLatin,
UnicodeRanges.Arabic }));
Arabic has quite a few blocks in Unicode, so you may need to add more blocks to get the full range you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With