首页 > 其他 > 详细

表单提交特殊字符处理

时间:2017-05-26 17:51:43      阅读:346      评论:0      收藏:0      [点我收藏+]

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

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

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

 

表单提交特殊字符处理

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!