Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET4.0
Hi,
I am sending a link in the email with query string to reset password. When user click on link this redirect to user on my website resetPwd.aspx and he/she can reset password successfully in database.
Again if the user is trying to open the link in email, its compulsory that it cant allow the user to open that link. How to block
the email link in the second click?
 

My C# code
 
    private void sendEmail(string emailTo, string userId)
    {
        string UserName = LoginUser.UserName;
        using (StreamReader reader = File.OpenText(Server.MapPath("~/App_Data/ResetPwdEmailBody.txt")))
        {
            string urlBase = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
            string verifyUrl = "/Account/UnlockAccount.aspx?uName=" + UserName + "&id=" + userId;
            string fullUrl = urlBase + verifyUrl;
            MailMessage msg = new MailMessage();
            msg.Subject = "Unlock your account";
            msg.IsBodyHtml = true;
            msg.To.Add(new MailAddress(emailTo, UserName));
            msg.Body = reader.ReadToEnd();
            msg.Body = msg.Body.Replace("<%resetPassword%>", fullUrl);
            msg.Body = msg.Body.Replace("<% UserName %>", UserName);
            msg.Priority = MailPriority.High;
            SmtpClient myClient = new SmtpClient();
            myClient.EnableSsl = false;
            try
            {
                myClient.Send(msg);
            }
            catch (Exception ex)
            {
                LoginUser.FailureText = "Email cannot be send. Error: " + ex.Message;
            }
        }
 
    }
 

Thanks in advance,
 
Ashok Luhach
Posted 1-Apr-13 22:43pm
Edited 1-Apr-13 23:03pm
v3
Comments
OriginalGriff at 2-Apr-13 3:47am
   
Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.
ashok luhach at 2-Apr-13 4:35am
   
thanks your idea is helpfull for me

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this link:
 

Sending reset password link for one time use only in asp.net
 

 

Don't forget to mark useful responses as Answer if they helped you towards a solution.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 209
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100