比较有效的,常用的防止sql注入攻击的方法有哪些? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不过要注意SQL注入,还有脚本注入,脚本就是要判断<了 多数都是脚本注入和SQL注入SQL注入一般性的实用 SqlParameter 就可以过滤掉,脚本要是想安全就自己写验证 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方法加入参数 1、参数化,不要拼凑sql,容易被别人 or 1=1 之类的操作2、过滤特殊字符 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误 如何让客户端只能同时开一个网站 各位高手请进,选项卡放在html显示正常,放在VS2008里没效果 页面加载问题 HttpHandler 一般性处理程序 服务和连接的外围应用配置 database engine 服务不能启动 DataList 如何获取 HeaderTemplate 里面的控件 如何做一个DataGrid,要求有翻页/跳页功能。 输入框回车事件与输入框历史信息的冲突??? 高手请 进! 如何设计框架? 请问为什么自定义控件中的背景图片不能显示?
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方法加入参数
2、过滤特殊字符