Click here to Skip to main content
16,007,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

C#
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
Updated 1-Apr-13 22:03pm
v3
Comments
OriginalGriff 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 2-Apr-13 4:35am    
thanks your idea is helpfull for me

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900