Net程序如何防止被注入
来源:互联网 发布:淘宝详情页ps切片 编辑:程序博客网 时间:2024/05/05 08:12
作者:未知 文章来源:骇客基地
防止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}) ___FCKpd___0quot;); } public static bool isUSZip(string zipString){ return System.Text.RegularExpressions.Regex.IsMatch(zipString ,"^-[0-9]+$|^[0-9]+___FCKpd___0quot;); } }
二、Web.config
在你的Web.config文件中,在下面增加一个标签,如下:
<appSettings> <add key="safeParameters" value="OrderID-int32,CustomerEmail-email,ShippingZipcode-USzip" /> </appSettings>
其中key是
三、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.Split('-')[0]; String parameterType = safeParameters.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"); } }
以后需要修改的时候我们只需要修改以上三个文件,对整个系统的维护将会大大提高效率,当然你可以根据自己的需要增加其它的变量参数和数据类型。
文章录入:温柔毒药 责任编辑:温柔毒药
- Net程序如何防止被注入
- .Net程序如何防止被注入(整站通用)
- .Net程序如何防止被注入(整站通用)
- .Net程序如何防止被注入(整站通用)
- Net程序如何防止被注入(整站通用)
- Net程序如何防止被注入(整站通用)
- .Net程序如何防止被注入(整站通用)
- .Net程序如何防止被注入(整站通用)
- Net程序如何防止被注入(整站通用)
- Net程序如何防止被注入整站通用
- .Net程序如何防止被注入(整站通用)
- .Net程序如何防止被注入(整站通用) [转]
- ASP.NET程序如何防止被注入(整站通用)
- ASP.NET程序如何防止被注入(整站通用)
- ASP.NET程序如何防止被注入(整站通用)
- ASP.NET程序如何防止被注入(整站通用)
- .net程序防止sql注入
- (转).Net程序如何防止被注入(整站通用)
- 关于level_idc
- 旁注资料最终版
- 需求评审
- EXE程序的自删除实现
- Eclipse常用插件下载地址
- Net程序如何防止被注入
- 北电大中国区总裁吴振生[zz]
- Previous Bio
- protel dxp 中的快捷键
- 反思今天
- 改变人生的32句励志名言
- C++英文面试题
- 人生警钟:商鞅职业生涯的启示
- 评谈:给编程初学者的良言警句