c# - Validating a simple login using LINQ -
i have datasource using linq need validate simple user, password against.
//load textfields local variables string user = username.text.tolower().trim(); string pass = userpass.text.tolower().trim(); //check credentials var xrm = new xrmservicecontext("xrm"); var inspectors = in xrm.systemuserset i.new_mobileappuser.equals(user.tostring()) select new { inspectorpass = i.new_mobileapppassword }; if (user == null || pass == null) { lblmsg.text = "you must enter valid username , password"; } if (inspectors == pass) { // (correct password) formsauthentication.redirectfromloginpage(username.text, chkpersistcookie.checked); response.redirect("/default.aspx"); } else { // else (incorrect password) lblmsg.text = "sorry, invalid credentials. please try again."; }
is there i'm missing here? i've followed other peoples examples , should able if inspectors == pass redirect. it's complaining cannot?
error message:-
error error 23 operator '==' cannot applied operands of type 'system.linq.iqueryable' , 'string' logon.aspx.cs
try this:
try { var inspector = inspectors.singleordefault(); if(inspector != null && inspector.inspectorpass == pass) {} } catch(){}
Comments
Post a Comment