A: 

ave a look here http://msdn.microsoft.com/en-us/library/ff649310.aspx

you can put a blanket statement in the web config ValidateRequest = true will check all user input and throw an error if a user inserts something with bad characters.

If you need to allow some html tags then you will need to roll your own.

Jonathan S.
+1 it's built-in... (handle the error of course).
Oskar Duveborn
-1: I don't believe throwing errors/exceptions to users is a good practice. And ValidateRequest = true does not cover all forms of XSS prevention, if that is the intention.
Caspar Kleijne
@Caspar Kleijne can you provide some references to ValidateRequest not covering all forms of XSS? I'm curious to read about it. I figured that microsoft would do a better job at catching all cases of dangerous user input better than i/ or the average developer could rolling their own.
Jonathan S.
ValidateRequest covers only forms of XSS-preventing that are known at the release of a certain version of (ASP).NET. .Net is not updated regularly on production servers. So if the server runs ASP.NET 2.0 or 3.5 (very common) most modern forms of XSS are unknown thus ignored. So it is a line of defense, but a weak one.
Caspar Kleijne
+1  A: 

The page will, by default, prevent users from posting HTML or script in textboxes or textareas. See MSDN

CyberDude
A: 

You can use a method to clean HTML codes from entry like:

public static string ClearHTML(string Str, Nullable<int> Character)
{
    string MetinTxtRegex = Regex.Replace(Str, "<(.|\n)+?>", " ");

    string MetinTxtSubStr = string.Empty;

    if (Character.HasValue)
    {
        if (MetinTxtRegex.Length > Character)
        {
            MetinTxtSubStr = MetinTxtRegex.Substring(0, Character.Value);
            MetinTxtSubStr = MetinTxtSubStr.Substring(0, MetinTxtSubStr.LastIndexOf(" ")) + "...";
        }
        else
        {
            MetinTxtSubStr = MetinTxtRegex;
        }
    }
    else
    {
        MetinTxtSubStr = MetinTxtRegex;
    }
    return MetinTxtSubStr;
}
Kaner TUNCEL
A: 

I've used:

HttpUtility.HtmlEncode();

More info here.

gmcalab