Escape string in C#

I have searched more than 30 min. for string escape method in C#, and finally here it is.

You can find it deep inside Security namspace

string safeString = System.Security.SecurityElement.Escape("St'ring to escpa");

You can use it to sanitize values before saving to database.

2 comments

  1. Well done my friend…!

  2. Bravo.

    The idiots at Microsoft are idiots because they believe making a parametrize query is the only way to one should build a query, however there are many use cases where you should escape the data instead.

    Data should be sanitized before it is stored as opposed to storing non-sanitized data and having to sanitize it going in and out of the database.

    This reduces the risk that you have while you try to work with business logic.

Leave a comment