作者:瑞铭与我_109 | 来源:互联网 | 2023-09-06 11:43
有很多方法可以保护Web应用免受 SQL注入的侵害,但这是否100%保证了质量?在我看来,存在一些绕过这些保护措施的方法:我真的不知道,使用注释,编码,HTTP参数污染可能找不到 ASP .NET Core 2.x
的任何示例
代码:
public DataTable GetUserDetailsbyId_ParameterizedQuery(string registrationId)
{
DataTable dt = new DataTable();
var cOnnection= "Server=(localdb)\\MSSQLLocaldb; Password=Pass$123;Database=AllSampleCode;Trusted_COnnection=True;";
using (SqlConnection con = new SqlConnection(connection))
{
con.Open();
var @query = "select * from Registration where RegistratiOnId=@RegistrationId";
SqlCommand cmd = new SqlCommand(query,con) { CommandType = CommandType.Text };
cmd.Parameters.AddWithValue("@RegistrationId",registrationId);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
}
return dt;
}
//////////////////////////////////////////////////////////////////////////////////////
public DataTable GetUserDetailsbyId_StoreProcedure(string registrationId)
{
DataTable dt = new DataTable();
var cOnnection= "Server=(localdb)\\MSSQLLocaldb; Password=Pass$123; Database=AllSampleCode;Trusted_COnnection=True;";
using (SqlConnection con = new SqlConnection(connection))
{
con.Open();
SqlCommand cmd = new SqlCommand("Usp_GetUserDetailsByRegistrationId",con);
cmd.Parameters.AddWithValue("@RegistrationId",registrationId);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter { SelectCommand = cmd };
da.Fill(dt);
}
return dt;
}