--写在存储过程中,防止SQL注入
CREATE PROCEDURE proc_test
@para1 INT = NULL,
@para2 VARCHAR(100) = NULL
AS
BEGIN
SELECT TOP 10 * FROM table_name
WHERE 1 = 1
AND (@para1 IS NULL OR field1 = @para1)
AND (@para2 IS NULL OR field2 = @para2)
END
--如果写在代码中,用拼SQL的方式,正好给SQL注入提供了入口
if (BusinessType != "请选择")
{
this.BusinessTypeDrop.Text = "test' or '1' = '1"; --可注入
where += " and BusinessType='" + this.BusinessTypeDrop.Text.ToString() + "'";
}
------解决方案-------------------- 写在里面也可能被注入啊。
------解决方案--------------------