欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET防止SQL注入的方法示例

 更新時(shí)間:2017年03月29日 14:22:06   作者:xyzqiang  
這篇文章主要介紹了ASP.NET防止SQL注入的方法,結(jié)合具體實(shí)例形式分析了asp.net基于字符串過濾實(shí)現(xiàn)防止SQL注入的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了ASP.NET防止SQL注入的方法。分享給大家供大家參考,具體如下:

最近接手別人一個(gè)項(xiàng)目,發(fā)現(xiàn)存在SQL注入漏洞,因?yàn)椴幌敫奶啻a,所以那種參數(shù)法防注入呢我就用不著了。只能用傳統(tǒng)的笨一點(diǎn)的辦法了。

1、新建Global.asax文件。

2、加入如下代碼:

void Application_BeginRequest(object sender, EventArgs e)
{
    bool result = false;
    if (Request.RequestType.ToUpper() == "POST")
    {
       //post方式的我就不寫了。
    }
    else
    {
      result = ValidUrlGetData();
    }
    if (result)
    {
      Response.Write("您提交的數(shù)據(jù)有惡意字符!");
      Response.End();
    }
}
/// <summary>
/// 獲取QueryString中的數(shù)據(jù)
/// </summary>
public static bool ValidUrlGetData()
{
    bool result = false;
    for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++)
    {
      result = Validate(HttpContext.Current.Request.QueryString[i].ToString());
      if (result)
      {
        break;
      }//如果檢測(cè)存在漏洞
    }
    return result;
}
public static string []strs = new string[] {"select","drop","exists","exec","insert","delete","update","and","or","user" };//此處我隨便加了幾個(gè),大家可以多加點(diǎn)哈。
public static bool Validate(string str)
{
    for (int i = 0; i < strs.Length; i++)
    {
      if (str.IndexOf(strs[i]) != -1)
      {
        return true;
        break;
      }
    }
    return false;
}

更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net優(yōu)化技巧總結(jié)》、《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。

希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論