防止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代码实例

asp.net如何利用ashx生成图形验证码的实例

asp.net 传值总结

asp.net core应用程序在linux上部署的图文详解

asp.net mvc部分视图渲染html的实例教程

asp.net控制文件上传的大小方法(超简单)_实用技巧

asp.net网站发布的过程详解

[asp.net mvc 小牛之路]07 - url routing

asp.net(三)web端展示

详细介绍《asp.net》数据绑定――gridview

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




打赏

取消

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

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

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

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

评论

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