如题

解决方案 »

  1.   

    不过要注意SQL注入,还有脚本注入,脚本就是要判断<了
      

  2.   

    多数都是脚本注入和SQL注入SQL注入一般性的实用 SqlParameter 就可以过滤掉,脚本要是想安全就自己写验证
      

  3.   


    string username = this.TextBox1.Text;
            string message = this.TextBox2.Text;
            string shortmessage;
            if (this.TextBox1.Text != "" && this.TextBox2.Text != "")
            {
                if (message.Length > 10)
                {
                    shortmessage = message.Substring(0, 10);
                    shortmessage += "...";
                }
                else
                    shortmessage = message;            DateTime posttime = System.DateTime.Now;
     SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyPageConnectionString"].ConnectionString);
                SqlCommand cmd = new SqlCommand("addmessage", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@username", username));
                cmd.Parameters.Add(new SqlParameter("@posttime", posttime));
                cmd.Parameters.Add(new SqlParameter("@message", message));
                cmd.Parameters.Add(new SqlParameter("@shortmessage", message));
                conn.Open();
                cmd.ExecuteNonQuery();
    定义存储过程,然后用add方法加入参数
      

  4.   

    1、参数化,不要拼凑sql,容易被别人 or 1=1 之类的操作
    2、过滤特殊字符