2

SqlCommand.Parameters.AddWithValue方法注入安全吗?

它接受Object有效载荷,那么它如何防止注入呢?

4

1 回答 1

7

这实际上取决于您如何使用它们。

看看这里的区别。第一个是安全的,但不是第二个。

sqlCommand.CommandText = "select * from Books where Title = @title";
sqlCommand.Parameters.AddWithValue("title", txtTitle.Text);

string sql = "select * from Books where title = " + txtTitle.Text;
sqlCommand.CommandText = "exec(@sql)";
sqlCommand.Parameters.AddWithValue("sql", sql);

在Does asp.net 防止 sql 注入攻击中查看有关它的更多详细信息

于 2012-10-19T01:56:49.543 回答