ASP.NET Core – How to receive a request with text/plain content

When a request comes in and your action method has parameters, the framework tries to find the appropriate InputFormatter to handle deserializing the request data. There’s no built-in text/plain InputFormatter though, so when you send a request with text/plain content, it fails with a 415 – Unsupported Media Type error response. In this article, I’ll … Read more

C# – Remove non-alphanumeric characters from a string

The simplest way to remove non-alphanumeric characters from a string is to use regex: Note: Don’t pass in a null, otherwise you’ll get an exception. Regex is the simplest options for removing characters by “category” (as opposed to removing arbitrary lists of characters or removing characters by position). The downside is that regex is the … Read more

C# – Using the ‘not’, ‘and’, ‘or’ operators

I’ll show examples of using the pattern matching operators – ‘not’, ‘and’, ‘or‘ – with the is operator. These are nice syntax sugar that make conditional logic a bit easier to read. Note: ‘not’, ‘and’, ‘or’ were added in C# 9. ‘not’ operator Here’s an example of the not operator: This is checking if the … Read more