csharp / beginner
Snippet
Basic Character Escaping for Security
Replacing sensitive characters like brackets helps prevent basic injection attacks when displaying user input.
snippet.cs
csharp
1
2
string input = "<script>";string safe = input.Replace("<", "<").Replace(">", ">");
Breakdown
1
input.Replace("<", "<")
Replaces the opening bracket with its HTML entity equivalent.