日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

整站如何防止SQL攻擊_.Net教程

編輯Tag賺U幣
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

推薦:總結(jié).NET開(kāi)發(fā)中ADO.NET的應(yīng)用
一、DataTable DataTable表示內(nèi)存中數(shù)據(jù)的一個(gè)表,它完全是在內(nèi)存中的一個(gè)獨(dú)立存在,包含了這張表的全部信息。DataTable可以是從通過(guò)連接從數(shù)據(jù)庫(kù)中讀取出來(lái)形成的一個(gè)表,一旦將內(nèi)容讀到DataTable中,此DataTable就可以跟數(shù)據(jù)源斷開(kāi)而獨(dú)立存在;也可以是完

    asp.net網(wǎng)站防止SQL注入攻擊,通常的辦法是每個(gè)文件都修改加入過(guò)濾代碼,這樣很麻煩,下面介紹一種辦法,可以從整個(gè)網(wǎng)站防止注入。 
    只要做到以下三點(diǎn),網(wǎng)站就會(huì)比較安全了而且維護(hù)也簡(jiǎn)單。  
    一、數(shù)據(jù)驗(yàn)證類(lèi)  
    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文件中,在下面增加一個(gè)標(biāo)簽,如下: 
<appSettings> 
    <add key="safeParameters" value="OrderID-int32,CustomerEmail-email,ShippingZipcode-
USzip" /> 
</appSettings>

    其中key是后面的值為“OrderId-int32”等,其中“-”前面表示參數(shù)的名稱(chēng)比如:OrderId,后面的int32表示數(shù)據(jù)類(lèi)型。 
    三、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"); 
    } 
}

    以后需要修改的時(shí)候大家只修改以上三個(gè)文件就可以了,整個(gè)系統(tǒng)的維護(hù)效率將會(huì)提高,當(dāng)然你也可以根據(jù)自己的需要增加其它的變量參數(shù)和數(shù)據(jù)類(lèi)型等等。

分享:關(guān)于Gridview的多種使用方法總結(jié)
asp.net中 Gridview的多種使用方法總結(jié),具體如下面 截圖,并包括詳細(xì)源代碼注釋?zhuān)枰恼?qǐng)下載。 1:在Gridview中無(wú)須編寫(xiě)后臺(tái)代碼,直接實(shí)現(xiàn)增除刪改 2:在Gridview中添加新記錄 3:在Gridview中實(shí)現(xiàn)編輯和更新操作 4:在Gridview中實(shí)現(xiàn)一次性更新所有記錄

來(lái)源:模板無(wú)憂(yōu)//所屬分類(lèi):.Net教程/更新時(shí)間:2010-05-20
相關(guān).Net教程