您现在的位置是:网站首页> 编程资料编程资料
ASP.NET防止SQL注入的方法示例_实用技巧_
2023-05-24
485人已围观
简介 ASP.NET防止SQL注入的方法示例_实用技巧_
本文实例讲述了ASP.NET防止SQL注入的方法。分享给大家供大家参考,具体如下:
最近接手别人一个项目,发现存在SQL注入漏洞,因为不想改太多代码,所以那种参数法防注入呢我就用不着了。只能用传统的笨一点的办法了。
1、新建Global.asax文件。
2、加入如下代码:
void Application_BeginRequest(object sender, EventArgs e) { bool result = false; if (Request.RequestType.ToUpper() == "POST") { //post方式的我就不写了。 } else { result = ValidUrlGetData(); } if (result) { Response.Write("您提交的数据有恶意字符!"); Response.End(); } } /// /// 获取QueryString中的数据 /// public static bool ValidUrlGetData() { bool result = false; for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++) { result = Validate(HttpContext.Current.Request.QueryString[i].ToString()); if (result) { break; }//如果检测存在漏洞 } return result; } public static string []strs = new string[] {"select","drop","exists","exec","insert","delete","update","and","or","user" };//此处我随便加了几个,大家可以多加点哈。 public static bool Validate(string str) { for (int i = 0; i < strs.Length; i++) { if (str.IndexOf(strs[i]) != -1) { return true; break; } } return false; } 更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net优化技巧总结》、《asp.net字符串操作技巧汇总》、《asp.net操作XML技巧总结》、《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。
您可能感兴趣的文章:
相关内容
- ASP.NET实现上传Excel功能_实用技巧_
- Visual Studio 2017设置版权的方法_实用技巧_
- Visual Studio 2017无法加载Visual Studio 2015创建的SharePoint解决方法_实用技巧_
- asp.net利用反射实现给model类赋值的方法_实用技巧_
- asp.net动态生成HTML表单的方法_实用技巧_
- 详解ASP.NET WEB API 之属性路由_实用技巧_
- MVC文件上传支持批量上传拖拽及预览文件内容校验功能_实用技巧_
- .net core版 文件上传/ 支持批量上传拖拽及预览功能(bootstrap fileinput上传文件)_实用技巧_
- ASP.NET MVC4 利用uploadify.js多文件上传_实用技巧_
- 模拟HTTP请求实现网页自动操作及数据采集的方法_实用技巧_
