-5
내 코드의 일부가 SQL 인젝션을받습니다. 아래 코드는SQL 인젝션을 극복하는 방법
public int Insert(string usrtest)
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(conn);
// SqlCommand cmd = new SqlCommand("select * from table where [email protected]", con);
SqlDataAdapter adp = new SqlDataAdapter("select * from table where [email protected]", con);
con.Open();
adp.SelectCommand.Parameters.AddWithValue("@name", usrtest);
adp.Fill(dt);
SqlCommand cmd1 = new SqlCommand("Update table set Date='" + DateTime.Now + "' where name='" + usrtest + "'", con);
cmd1.ExecuteNonQuery();
con.Close();
}
두 코드의 차이점을 모르시겠습니까? 먼저 매개 변수화 된 쿼리를 적절히 사용하면 모든 것을 무시하고 문자열 연결을 통해 SQL을 다시 작성합니다. 또한 두 번째 쿼리에서 매개 변수를 사용하면 작업이 완료됩니다. – CodeCaster
또한 SqlConnection, SqlCommand 및 SqlDataAdapter에 "using"문을 사용해야합니다. https://www.dotnetperls.com/sqlconnection 및 http://stackoverflow.com/questions/18205560/do-i-need- to-explicit-dispose-sqldataadapter입니다. – Polyfun
편집을 가능하게하는 gridview에 대한 itemtemplate 텍스트 박스 컨트롤이 있습니다. 이것은 코드입니다 이 사이트에 크로스 사이트가 있습니까? (예 : "% 스크립트 위험? – Aswini