ASP.NET MVC: Simple SQL Injection security
I'm developing an ASP.NET MVC 3 app and need a way around S开发者_StackOverflow中文版QL injections, something simple would be useful. I have followed Microsoft's article on the matter but it doesn't seem to match up with my code and structure.
Any help is greatly appreciated
To prevent sql injection:
Do not form any dynamic sql.
- Use stored procedures (and do not include any dynamic sql in a stored proc - if you do make sure you use sp_executesql and not exec, as sp_executesql can take a parameterized query
- use parameterized queries
- use an ORM (ex. entity framework) which uses parameterized queries behind the scenes anyways.
try not to use any dynamic sql - if you must for some reason then make sure you use parameterized queries.
Don't just simply use dynamic sql and remove quotes from them - its a bit dangerous to assume that would be the only attack vector as some do.
精彩评论