What is the best practice for handling dangerous characters in asp.net?
I did not watch the screencast you are referring to (questions should be self-contained in any case), but there are no dangerous characters . It all depends on the context. For example, let's take a stack overflow, it allows you to enter Dangerous!'); DROP TABLE Questions-- characters Dangerous!'); DROP TABLE Questions-- Dangerous!'); DROP TABLE Questions-- . Nothing dangerous there.
ASP.NET itself will do everything possible to prevent malicious input at the HTTP level: it will not allow any user to access files like web.config or files outside of your web root.
Once you start doing something with user input, it's up to you. There is not a single silver bullet, not a single rule that would correspond to all of them. If you intend to display user input as HTML, you need to make sure that you enable harmless markup labels without the attributes available to the script. If you allow users to upload images, make sure that only images are uploaded. If you intend to send input to an RDBMS, be sure to avoid characters that make sense for the database manipulation language.
And so on.
source share