首页 > 代码库 > 表单提交特殊字符处理
表单提交特殊字符处理
项目中经常会用到表单提交特殊字符过滤。
之前经常每次用的时候查下,解决了,就完了。这次记录下。
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
表单提交特殊字符处理
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。