码迷,mamicode.com
首页 > 其他好文 > 详细

表单提交特殊字符处理

时间:2017-05-26 17:57:14      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:targe   添加   hit   htm   tar   hle   字符   ==   方法   

项目中经常会用到表单提交特殊字符过滤。

之前经常每次用的时候查下,解决了,就完了。这次记录下。

1.前台做过滤

1  function fiterJSONStr(str) {
2     str = str.replace(/\\/g, ‘\\\\‘);
3     str = str.replace(/&/g, ‘jq==‘);//后端需要做下处理
4     str = str.replace(/‘/g, ‘’‘);
5     str = str.replace(/"/g, ‘”‘);
6     str = str.replace(/</g, ‘‘);
7     str = str.replace(/>/g, ‘‘);
8     return str.replace(/"/g, ‘“‘);
9 }

2. 后端处理

使用.NET MVC 只需要在方法前面加上[ValidateInput(false)] 属性

然后还需要再web.config 添加 <httpRuntime requestValidationMode="2.0" />

 

以上。

 

原文:http://www.cnblogs.com/bigbrid/p/6909716.html 

作者:hito

 

表单提交特殊字符处理

标签:targe   添加   hit   htm   tar   hle   字符   ==   方法   

原文地址:http://www.cnblogs.com/bigbrid/p/6909716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!