
- 加为好友
- 发送私信
- 在线聊天
|
| 发表于:2008-05-29 22:56:2034楼 得分:0 |
简单的ASP.net防SQL注入2008-01-27 18:22防sql注入是每个开发人员都要考滤的问题 asp.net有个Global.asax文件,有一个Application_BeginRequest方法(应用启动获取) 就是当获取到参数时触发的事件;这里就是网站页面每次提交时都要经过的事件;在这里做防注入就一下子卡住入口了 代码如下: protected void Application_BeginRequest(Object sender, EventArgs e) { //遍历Post参数,隐藏域除外 foreach (string i in this.Request.Form) { //输出 } //遍历Get参数。 foreach (string i in this.Request.QueryString) { //输出 } } 这样就可以遍历出页面提交上来的所有的参数;里面只写了一个“//输出”,没有写代码出来,大家可以写repsonse.write输出来看看,尝试一下;我们只需对这些参数进行过滤,如果存在不安全字符,直接跳转就走行了; 也可以加过滤 public static string DelSQLStr(string str) { if(str == null ¦ ¦ str == "") return ""; str = str.Replace(";",""); str = str.Replace("'",""); str= str.Replace("&",""); str= str.Replace("%20",""); str= str.Replace("--",""); str= str.Replace("==",""); str= str.Replace(" <",""); str= str.Replace(">",""); str= str.Replace("%",""); | | |
修改
删除
举报
| |