All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
经典php实现大文件上传源代码_[PHP教程]
AjaxPro与服务器端交互过程中如何传值_[AJAX教程]
PHP5连接Mysql5的认证协议问题_php资料_编程技术
教你用PHP写MySQL数据库用户认证系统_php资料_编程技术
实例:在ASP.NET中创建使用全球唯一标识符_.net资料_编程技术
教你如何在Perl下连接Access数据库_php资料_编程技术
怎样从ASP.NET,2.0中读取连接字符串的设置_[Asp.Net教程]
常用的二十六个优化性能方法(ASP.NET)_[Asp.Net教程]
C#中利用process类调用外部程序以及执行dos命令_.net资料_编程技术
Visual,C#命名空间详解_[Asp.Net教程]
Reading number is top 10 pictures
Athena chu perspective cheongsam shine with New York
The goddess of the single reason2
这是男生笨么?
七步解决性冷淡
人美胸美腿更美1
Valentine's day comes, send some cartoon
怀春少女-石一伊
A man's favorite things16
Seductive beauty of crime1
有种屌丝级别的好妹子
Download software ranking
Unix video tutorial17
尖东毒玫瑰A
Tram sex maniac 2 (H) rar bag16
asp.net技术内幕
Boxer Classic video2
功夫熊猫2(上集)
传奇私服架设教程
VC++6.0简体中文版
Proficient in Eclipse
Dance with duck(male prostitution)
归海一刀 published in(发表于) 2014/1/30 1:37:09 Edit(编辑)
整站如何防止SQL注入攻击_[Asp.Net教程]

整站如何防止SQL注入攻击_[Asp.Net教程]

整站如何防止SQL注入攻击_[Asp.Net教程]
asp.net网站防止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文件中,在下面增加一个标签,如下:





其中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");
}
}

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


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.