.NET: Text censoring with custom list

Mustafa Ahmed
1 min readMay 24, 2022

Any service that allows user-generated content brings with it a risk of content that can negatively impact your actual userbase’s experience.

There’s multiple ways you can moderate content. The ideal way would be use a content moderator service like Azure Content Moderator that uses AI to rate the content with a racy-score, giving you the ability to fine tune moderation based on your specific use-case. It can act as middleware between your insert call and automatically reject or accept posts. While not too expensive, its still a paid service.

When I was working with user-generated content, I decided I would allow the users to post whatever they like. However, when user content is fetched from the API, I added custom middleware that censors only the bad words from within a whole text and replaces it with asterisks.

The downside is that your censoring is only as good as the list you are filtering on. But the upside is that you still get the relevant part of the content while also protecting your userbase from unpleaseant language.

This was done quite some time ago and I can’t remember if I wrote this censor class myself or if I improved on it from some other source or if I copied all of it.

The list you can find here. I have compiled it by combining various resources, containing multiple languages — with a few additions of my own.

--

--