<%@ Application Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>

<script runat="server">
  protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        //SQL防注入 
        string Sql_1 = "exec|insert+|select+|delete+|update+|mid|master+|truncate|declare|drop+|drop+table|creat+|creat+table";
        string Sql_2 = "exec+|insert|insert+|delete+|update+(|count+|+mid(|+mid+|+master+|truncate+|+char(|declare+|drop+|creat+|drop+table|creat+table";
        string[] sql_c = Sql_1.Split('|');
        string[] sql_c1 = Sql_2.Split('|');

        if (Request.QueryString != null)
        {
            foreach (string sl in sql_c)
            {
                if (Request.QueryString.ToString().ToLower().IndexOf(sl.Trim()) >= 0)
                {
                    Response.Write("Warning! Your IP has been recorded! Do not use a sensitive character");// 
                    Response.Write(sl);
                    Response.Write(Request.QueryString.ToString());
                    Response.End();
                    break;
                }
            }
        }

        if (Request.Form.Count > 0)
        {
            string s1 = Request.ServerVariables["SERVER_NAME"].Trim();//服务器名称 
            if (Request.ServerVariables["HTTP_REFERER"] != null)
            {
                string s2 = Request.ServerVariables["HTTP_REFERER"].Trim();//http接收的名称 
                string s3 = "";
                if (s1.Length > (s2.Length - 7))
                {
                    s3 = s2.Substring(7);
                }
                else
                {
                    s3 = s2.Substring(7, s1.Length);
                }
                if (s3 != s1)
                {
                    Response.Write("Warning! Your IP has been recorded! Do not use a sensitive character！");// 
                    Response.End();
                }
            }
        }
    } 
    void Application_Start(object sender, EventArgs e) 
    {
        //
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  在应用程序关闭时运行的代码

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // 在出现未处理的错误时运行的代码

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // 在新会话启动时运行的代码

    }

    void Session_End(object sender, EventArgs e) 
    {
        // 在会话结束时运行的代码。 
        // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
        // InProc 时，才会引发 Session_End 事件。如果会话模式设置为 StateServer 
        // 或 SQLServer，则不会引发该事件。

    }
    
       
</script>
