Linq to SQL and SQL Injection

a 夏天 提交于 2019-12-12 18:16:26

问题


What do I need to add, if I need to at all, to avoid sql injections?

public static Login GetLoginByName(string name)
{
    var context=new telephonyEntities1();

    Login t = (from l in context.Logins
               where l.login1==name
               select l).FirstOrDefault();
    return t;
}

回答1:


Linq-to-sql uses SqlParameter to generate SQL queries, so no you do not need to do anything extra.

From Frequently Asked Questions (LINQ to SQL)

Q. How is LINQ to SQL protected from SQL-injection attacks?

A. SQL injection has been a significant risk for traditional SQL queries formed by concatenating user input. LINQ to SQL avoids such injection by using SqlParameter in queries. User input is turned into parameter values. This approach prevents malicious commands from being used from customer input.



来源:https://stackoverflow.com/questions/5893743/linq-to-sql-and-sql-injection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!