I think you are attacking it from the wrong angle by trying to encode all posted data.
Note that a "
<" could also come from other outside sources, like a database field, a configuration, a file, a feed and so on.
<" is not inherently dangerous. It's only dangerous in a specific context: when writing strings that haven't been encoded to HTML output (because of XSS).
In other contexts different sub-strings are dangerous, for example, if you write an user-provided URL into a link, the sub-string "
The bottom line is: you can't filter random input for dangerous characters, because any character may be dangerous under the right circumstances. You should encode at the point where some specific characters may become dangerous because they cross into a different sub-language where they have special meaning. When you write a string to HTML, you should encode characters that have special meaning in HTML, using Server.HtmlEncode. If you pass a string to a dynamic SQL statement, you should encode different characters (or better, let the framework do it for you by using prepared statements or the like)..
When you are sure you HTML-encode everywhere you pass strings to HTML, then set
ValidateRequest="false" in the
<%@ Page ... %> directive in your
In .NET 4 you may need to do a little more. Sometimes it's necessary to also add
<httpRuntime requestValidationMode="2.0" /> to web.config (reference).
eval() is not necessary. This will work fine:
var date = new Date(parseInt(jsonDate.substr(6)));
substr() function takes out the
/Date( part, and the
parseInt() function gets the integer and ignores the
)/ at the end. The resulting number is passed into the
I have intentionally left out the radix (the 2nd argument to
parseInt); see my comment below.
Also, I completely agree with Rory's comment: ISO-8601 dates are preferred over this old format - so this format generally shouldn't be used for new development.
For ISO-8601 formatted JSON dates, just pass the string into the
var date = new Date(jsonDate); //no ugly parsing needed; full timezone support
I only know of 2 open source forums for ASP.NET
The first one, Yet Another Forum is probably your best bet. It supports Unicode (UTF-8).