此方法用于确认用户输入的不是恶意信息
2008-02-22 09:42:07来源:互联网 阅读 ()
![新老客户大回馈,云服务器低至5折](/info/templets/default/images/760x90_D.jpg)
/// <summary>
/// 此方法用于确认用户输入的不是恶意信息
/// </summary>
/// <param name="text">用户输入信息</param>
/// <param name="maxLength">输入的最大长度</param>
/// <returns>处理后的输入信息</returns>
public static string InputText(string text, int maxLength) {
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
if (text.Length > maxLength)
text = text.Substring(0, maxLength);
//将网页中非法和有攻击性的符号替换掉,以防sql注入!返回正常数据
text = Regex.Replace(text, "[\\s]{2,}", " "); // 2个或以上的空格
text = Regex.Replace(text, "(<[b|B][r|R]/*>) |(<[p|P](.|\\n)*?>)", "\n"); //<br> html换行符
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*) ", " "); // html空格符
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); // 任何其他的标签
text = text.Replace("'", "''");// 单引号
return text;
}
http://www.cnblogs.com/wang123/archive/2007/01/16/622035.html
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash