自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

網(wǎng)站安全:整站如何防止SQL注入方式入侵

安全 應用安全
防止SQL注入,通常一個一個文件修改不僅麻煩而且還有漏掉的危險,下面我說一下如何從整個系統(tǒng)防止注入。

防止SQL注入,通常一個一個文件修改不僅麻煩而且還有漏掉的危險,下面我說一下如何從整個系統(tǒng)防止注入。

做到以下三步,相信你的程序就會比較安全了,而且對整個網(wǎng)站的維護也將變的簡單。

一、數(shù)據(jù)驗證類

parameterCheck.cs 

  

public class parameterCheck{

    public static bool isEmail(string emailString){

        return System.Text.RegularExpressions.Regex.IsMatch(emailString, "['\\w_-]+(\\.

['\\w_-]+)*@['\\w_-]+(\\.['\\w_-]+)*\\.[a-zA-Z]{2,4}");

    }

    public static bool isInt(string intString){

        return System.Text.RegularExpressions.Regex.IsMatch(intString ,"^(\\d{5}-\\d{4})|

(\\d{5})$");

    }

    public static bool isUSZip(string zipString){

        return System.Text.RegularExpressions.Regex.IsMatch(zipString ,"^-[0-9]+$|^[0-9]

+$");

    }

}

二、Web.config

在你的Web.config文件中,在下面增加一個標簽,如下:

    USzip" />

其中key是后面的值為“OrderId-int32”等,其中“-”前面表示參數(shù)的名稱比如:OrderId,后面的int32表示數(shù)據(jù)類型。

三、Global.asax

在Global.asax中增加下面一段:

protected void Application_BeginRequest(Object sender, EventArgs e){

    String[] safeParameters = System.Configuration.ConfigurationSettings.AppSettings

["safeParameters"].ToString().Split(',');

    for(int i= 0 ;i < safeParameters.Length; i++){

        String parameterName = safeParameters[i].Split('-')[0];

        String parameterType = safeParameters[i].Split('-')[1];

        isValidParameter(parameterName, parameterType);

    }

} 

 

public void isValidParameter(string parameterName, string parameterType){

    string parameterValue = Request.QueryString[parameterName];

    if(parameterValue == null) return;

 

    if(parameterType.Equals("int32")){

        if(!parameterCheck.isInt(parameterValue)) Response.Redirect("parameterError.aspx");

    }

    else if (parameterType.Equals("double")){

        if(!parameterCheck.isDouble(parameterValue)) Response.Redirect("parameterError.aspx");

    }

    else if (parameterType.Equals("USzip")){

        if(!parameterCheck.isUSZip(parameterValue)) Response.Redirect("parameterError.aspx");

    }

    else if (parameterType.Equals("email")){

        if(!parameterCheck.isEmail(parameterValue)) Response.Redirect("parameterError.aspx");

    }

}

以后需要修改的時候我們只需要修改以上三個文件,對整個系統(tǒng)的維護將會大大提高效率,當然你可以根據(jù)自己的需要增加其它的變量參數(shù)和數(shù)據(jù)類型。

責任編輯:佚名 來源: 賽迪網(wǎng)
相關推薦

2020-09-28 09:30:13

mybatis

2020-08-07 08:13:08

SQL攻擊模式

2023-08-01 08:00:00

SQLWeb應用安全

2011-03-08 09:41:49

2011-06-20 10:19:29

2023-03-24 10:28:27

2011-06-20 10:19:31

2009-02-04 16:51:48

2009-07-24 16:59:57

iBatis模糊查詢

2010-10-22 15:18:18

SQL注入漏洞

2012-11-08 17:02:58

2013-01-05 13:49:00

2014-05-26 09:32:15

2009-03-10 08:05:19

2011-12-30 11:04:14

2010-09-25 14:26:21

2010-08-30 09:50:34

2013-04-26 11:26:00

2017-03-01 14:16:20

2020-10-10 10:10:07

安全漏洞技術
點贊
收藏

51CTO技術棧公眾號