c# - How to solve the error occurred in password recovery? -
i'm using asp.net c# ef , i'm trying reset password when user forget it. , in there i'm sending email link user's provided email if in database.
but it'll give me error @ point member = membership.getuser(foundemail); saying
{"an error occurred while attempting initialize system.data.sqlclient.sqlconnection object. value provided connection string may wrong, or may contain invalid syntax.\r\nparameter name: connectionstring"}
here code in controller
[httppost] [allowanonymous] [validateantiforgerytoken] public actionresult resetpassword(resetpasswordmodel resetpasswordmodel) { if (modelstate.isvalid) { //user user; membershipuser member; using (thefoodycontext db = new thefoodycontext()) { /*var foundemail = (from e in db.users e.email == resetpasswordmodel.email select e.email).firstordefault();*/ var foundemail = (db.users.find(resetpasswordmodel.email)).email.tostring(); if (foundemail != null) { member = membership.getuser(foundemail); } else { member = null; } } if (member != null) { //generate password token used in email link authenticate user var token = websecurity.generatepasswordresettoken(member.email); // generate html link sent via email string resetlink = "<a href='" + url.action("resetpasswordview", "account", new { rt = token }, "http") + "'>reset password link</a>"; // email stuff string subject = "reset password thefoody.com"; string body = "you link: " + resetlink; string = "abcd123@gmail.com"; string = resetpasswordmodel.email; system.net.mail.mailmessage message = new system.net.mail.mailmessage(from, to); message.subject = subject; message.body = body; smtpclient client = new smtpclient(); // attempt send email try { client.send(message); } catch (exception e) { modelstate.addmodelerror("", "issue sending email: " + e.message); } } else // email not found { modelstate.addmodelerror("", "no user found email."); } } return view(resetpasswordmodel); }
and here connectionstring in web.config
<add name="thefoodycontext" connectionstring="metadata=res://*/thefoodymodel.csdl|res://*/thefoodymodel.ssdl|res://*/thefoodymodel.msl;provider=system.data.sqlclient;provider connection string="data source=desktop-njoqtok;initial catalog=thefoody;integrated security=true;multipleactiveresultsets=true;app=entityframework"" providername="system.data.entityclient" />
i'm new environment , can me?
Comments
Post a Comment