Using HTML Entity Encoder: practical guide
Show markup as text safely
Encoding replaces characters like <, > and & with entities so a browser displays them instead of treating them as HTML. Use it when you want to show a code snippet on a page.
Encoding is not a full security measure
Escaping output in the right context is one part of preventing injection attacks, but different places, such as HTML text, attributes and scripts, need different escaping. For user input in an application, rely on your framework's built-in escaping.