资源简介
c# 全站防止sql注入,利用Global.asax、Appcode中添加类的方法
代码片段和文件信息
//code by D.
using System;
using System.Web;
using System.Text;
using System.Text.Regularexpressions;
public class safe_360
{
private const string StrRegex = @“^\+/v(8|9)|\b(and|or)\b.{16}?(=|>|<|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATAbase)“;
public static bool PostData()
{
bool result = false;
for (int i = 0; i < HttpContext.Current.Request.Form.Count; i++)
{
result = CheckData(HttpContext.Current.Request.Form[i].ToString());
if (result)
{
break;
}
}
return result;
}
public static bool GetData()
{
bool result = false;
for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++)
{
result = CheckData(HttpContext.Current.Request.QueryString[i].ToString());
if (result)
{
break;
}
}
return result;
}
public static bool CookieData()
{
bool result = false;
for (int i = 0; i < HttpContext.Current.Request.Cookies.Count; i++)
{
result = CheckData(HttpContext.Current.Request.Cookies[i].Value.ToLower());
if (result)
{
break;
}
}
return result;
}
public static bool referer()
{
bool result = false;
return result = CheckData(HttpContext.Current.Request.UrlReferrer.ToString());
}
public static bool CheckData(string inputData)
{
if (Regex.IsMatch(inputData StrRegex))
{
return true;
}
else
{
return false;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1916 2015-05-15 18:19 360safe.cs
文件 2399 2015-05-15 18:18 Global.asax
文件 2512 2013-04-19 22:38 使用说明.txt
----------- --------- ---------- ----- ----
6827 3
评论
共有 条评论