开发者

Preventing quotes causing a HttpRequestValidationException

To prevent a HttpRequestValidationException I httpEncode (using a javascript library) my input to send it to the server, where it is httpencoded again and stored. Then process it reversed to get it back, with an extra encode added if it's going into a label.

This seems to work fine but I get a HttpRequestValidationExceptio开发者_StackOverflow社区n if I put a single quote into my textbox. The httpEncode changes this to a ' which seems to be what it triggering the validation error. Is there a workaround? I can't afford to turn off page validation at the page level. Also, is this error likely to occur for other characters I haven't yet discovered?

Seems odd that it would choose that as potentially dangerous, when <html> produces no validation problem. Also " encodes to " without a problem.


I've encountered the same problem. Amazing how difficult it is to fix this one.

I've ended up using javascript to replace my apostrophes with a token that I re-replace on the server. I'm posting my code snips below, but these are pretty specific to my situation.

Javascript (Client):
convertedString = originalString.replace(/\'/g, '&apos2;');

ASP.NET (Server):
originalString = HttpUtility.HtmlDecode(
        HttpUtility.HtmlDecode(convertedString)
    ).Replace("&apos2;", "'");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜