文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页技术开发数据库安全 → 整站如何防止SQL注入方式入侵

整站如何防止SQL注入方式入侵

时间:2010/4/13 17:29:00来源:本站整理作者:我要评论(0)

整站如何防止SQL注入方式入侵?

防止SQL注入,通常一个一个文件修改不仅麻烦而且还有漏掉的危险,下面我说一下如何从整个系统防止注入。

做到以下三步,相信你的程序就会比较安全了,而且对整个网站的维护也将变的简单。

一、数据验证类

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”等,其中“-”前面表示参数的名称比如:OrderId,后面的int32表示数据类型。

三、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");

    }

}

以后需要修改的时候我们只需要修改以上三个文件,对整个系统的维护将会大大提高效率,当然你可以根据自己的需要增加其它的变量参数和数据类型。

相关视频

    没有数据

相关阅读 Mac OS X 系统上如何升级 Mysql 数据库?PLSQL Developer怎么导出数据库PLSQL Developer配置Oralce11g连接plsql developer怎么使用 plsql developer使用教程plsql developer怎么连接数据库 plsql developer连接数据库教程SQL2008全部数据导出导入两种方法mysql数据库root密码忘记的修改方法SQL报表错误“未能为SSL/TLS安全通道建立信任关系”解决方法

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 没有查询到任何记录。 数据库安全技术研究如何看清楚SQL注入SQL SERVER数据库口令的脆弱性MySQL不安全临时文件建立漏洞

人气排行 MySQL3.23.31之前版本的安全漏洞网站入侵过程!如何看清楚SQL注入通过mysql入侵NT和win2000Mysql数据库的安全配置、实用技巧SQL数据库的一些攻击 SQL Server补丁安装常见问题SQL SERVER数据库口令的脆弱性