防止SQL注入的ASP.NET方法实例解析


当前第2页 返回上一页

2、加入如下代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

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();

    }

}

/// <summary>

/// 获取QueryString中的数据

/// </summary>

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;

}

以上就是防止SQL注入的ASP.NET方法实例解析的详细内容!

返回前面的内容

相关阅读 >>

asp.net中md5加密码的代码详解

asp.net动态输出404 http状态代码

关于asp.net如何利用ajaxpro完成前端跟后台交互的实例分析

mvc页面重定向的asp代码讲解

详细介绍一款.net代码编辑控件(icsharpcode.texteditor)

如何使用会话状态(asp.net web 服务)

asp.net mvc 使用bootstrap方法介绍

asp.net是什么

asp.net页脚制作详解

传播智客asp.net基础系列视频资料分享

更多相关阅读请进入《asp.net》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...