zoukankan      html  css  js  c++  java
  • 防代码注入

    有些网站特别容易受到攻击,所以我们要写一写东西防止代码注入,首先我们新建一个global.asax文件并在该global.asax.cs文件中添加

     1     protected void Application_BeginRequest(object sender, EventArgs e)
     2         {
     3             //遍历Post参数,隐藏域除外
     4             foreach (string i in this.Request.Form)
     5             {
     6                 if (i == "__VIEWSTATE") continue;
     7                 this.goErr(this.Request.Form[i].ToString());
     8             }
     9             //遍历Get参数。
    10             foreach (string i in this.Request.QueryString)
    11             {
    12                 this.goErr(this.Request.QueryString[i].ToString());
    13             }
    14 
    15         }
    16 
    17         private void goErr(string tm)
    18         {
    19             if (SqlFilter2(tm))
    20             {
    21                 Response.Redirect("Default.aspx");
    22                 Response.End();
    23             }
    24         }
    25 
    26         public static bool SqlFilter2(string InText)
    27         {
    28             string word = ConfigurationManager.AppSettings["SeqKey"];
    29             if (InText == null)
    30                 return false;
    31             foreach (string i in word.Split('|'))
    32             {
    33                 if ((InText.ToLower().IndexOf(i + " ") > -1) || (InText.ToLower().IndexOf(" " + i) > -1))
    34                 {
    35                     return true;
    36                 }
    37             }
    38             return false;
    39         }

    同时我们要在web.config文件中添加一个节点

    1 <appSettings>
    2     <add key="ShangYe.Common:DatabaseVersion" value="SQLServer2000"/>
    3     <add key="SeqKey" value="and|exec|insert|select|delete|update|chr|mid|master|or|truncate|char|declare|join"/>
    4   </appSettings>
  • 相关阅读:
    Rust-数据类型
    Rust-智能指针
    Rust-使用包、Crate和模块管理不断增长的项目
    Rust-Slice类型
    Rust-引用与借用
    Rust 的核心功能-所有权(ownership)
    How to fix “sudo: command not found error”
    ABC195 F
    CF1501D Two chandeliers【拓展欧几里得+二分】
    CCA的小球【容斥定理】
  • 原文地址:https://www.cnblogs.com/tl2f/p/5412697.html
Copyright © 2011-2022 走看看