Click here to Skip to main content
11,805,316 members (66,644 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET4
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;
        catch (Exception ex)
            LoginUser.FailureText = "Email cannot be send. Error: " + ex.Message;

Thanks in advance,

Ashok Luhach
Posted 1-Apr-13 21:43pm
Edited 1-Apr-13 22:03pm
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
Please Sign up or sign in to vote.

Solution 1

Try this link:

Sending reset password link for one time use only in

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

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

  Print Answers RSS
0 OriginalGriff 3,265
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2015
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