I have an ASP.NET WebForms application. I’m setting the page’s title based on content from my database.
Because this content is entered by the user, it can contain any characters, including ones that could be interpreted as HTML markup. Therefore, I am HTML-encoding this content before setting the title.
But I see this is causing problems by producing overly encoded results:
<title>Hoigaard&#39;s Nordic Walking Tuesdays</title>
What is the correct way to safely encode text used to set the title tag?
I tested this, and it appears setting
Page.Titlealready performs the encoding. So your additional encoding is resulting in double-encoded results. Just set thePage.Titledirectly:result: