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 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web02 | 2.8.141220.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