我正在建立一個公共站點,我首先想到的是SQL注入。我有一些我正在保存的文本字段,正在使用linq來更新/寫入數據庫。我安全使用LINQ?將使用LINQ to SQL幫助防止SQL注入
本示例創建用戶帳戶。
Data.MemberRegistrationDataContext context = new MemberRegistrationDataContext();
Data.tbl_Member_UserProfile profile = new tbl_Member_UserProfile();
profile.SSN = Convert.ToDecimal(Session["tempMemberSSN_Registration"]);
profile.UserName = userName;
profile.Password = password;
profile.EmailAddress = email;
profile.QuestionID = qID;
profile.QuestionResponse = securityAnswer;
profile.LastModDt = DateTime.Now;
profile.LastModBy = "web";
context.tbl_Member_UserProfiles.InsertOnSubmit(profile);
context.SubmitChanges();
這個例子是改變密碼
MemberRegistrationDataContext dc = new MemberRegistrationDataContext();
var mProfileRecord = dc.tbl_Member_UserProfiles.Single(c => c.SSN == sSSN);
mProfileRecord.Password = sNewPassword;
dc.SubmitChanges();
這些是安全的? LINQ是否會自動生成它生成的SQL參數?
讀者注意:實體框架也是如此。請參閱http://stackoverflow.com/questions/3473841/entity-framework-linqtosql-and-sql-injection – 2013-07-03 20:33:38