ASP.net简单的防SQL注入代码
来源:互联网 发布:win10 正在准备windows 编辑:程序博客网 时间:2024/05/14 21:20
ASP.net简单的防SQL注入代码
一,验证方法
/// <summary>
///SQL注入过滤
/// </summary>
/// <param name="InText">要过滤的字符串</param>
/// <returns>如果参数存在不安全字符,则返回true</returns>
public static bool SqlFilter2(string InText)
{
string word="and|exec|insert|select|delete|update|chr|mid|master|or|truncate|char|declare|join";
if(InText==null)
return false;
foreach(string i in word.Split('|'))
{
if((InText.ToLower().IndexOf(i+" ")>-1)||(InText.ToLower().IndexOf(" "+i)>-1))
{
return true;
}
}
return false;
}
二,Global.asax 事件
/// <summary>
/// 当有数据时交时,触发事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_BeginRequest(Object sender, EventArgs e)
{
//遍历Post参数,隐藏域除外
foreach(string i in this.Request.Form)
{
if(i=="__VIEWSTATE")continue;
this.goErr(this.Request.Form.ToString());
}
//遍历Get参数。
foreach(string i in this.Request.QueryString)
{
this.goErr(this.Request.QueryString[i].ToString());
}
}
三,Global中的一个方法
/// <summary>
/// 校验参数是否存在SQL字符
/// </summary>
/// <param name="tm"></param>
private void goErr(string tm)
{
if(WLCW.Extend.CValidity.SqlFilter2(tm))
this.Response.Redirect("/error.html");
}
- ASP.net简单的防SQL注入代码
- ASP.net简单的防SQL注入代码
- ASP.net简单的防SQL注入代码
- 简单的ASP.net防SQL注入
- 简单的ASP.net防SQL注入
- 简单的ASP.net防SQL注入
- 简单的ASP.net防SQL注入
- ASP.net防SQL注入(简单)
- ASP.net防SQL注入(简单)
- ASP.net防SQL注入(简单)
- ASP.net防SQL注入(简单)
- asp.net(C#)防sql注入组件的实现代码
- asp.net防SQL注入的安全措施
- asp.net的sql防注入
- asp.net防SQL注入的安全措施
- ASP网页防SQL注入的代码
- ASP.net防SQL注入
- ASP.net防SQL注入
- 八皇后问题的位操作解法
- ASP.NET中常用的26个优化性能方法
- asp.net中将各种视频文件转换成.flv格式
- C#中的cookie编程
- JSP活动头像上传
- ASP.net简单的防SQL注入代码
- 一个分页用的存储过程(转)
- MS SQL中簡繁互轉查詢實現
- Do All in Cmd Shell
- 用Ndiswrapper在Linux中配置无线网卡
- 使用User Control做HTML生成
- 如何在多个网络环境中自由切换
- 今天开博
- C#优化字符串操作