How to cleanse a string

Keith Viking 20 Reputation points
2023-05-03T14:59:12.64+00:00

Hi I have a message box on a site. They can enter any characters and submit the form. In Asp.Net webforms we could add decode or encode to stop malicious content from being submitted but what would the equivalent be for MVC (.Net 6) so I can clean the string before storing in a database or sending as an email? I have added the attribute [validateantiforgerytoken] to the POST method.

Developer technologies | ASP.NET | ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2023-05-03T15:07:48.9033333+00:00

    Proper html escape on display is preferred. But you can find html sanitization libraries if you google.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.