2016-02-13 61 views
-1

進程加載的鏈接頁面檢測到它:傳遞一些參數與鏈接,並同時使用C#

  1. 發送電子郵件至特定的用戶和郵件正文中包含獨特的聯繫。
  2. 同時我需要在該用戶的數據庫中存儲該唯一鏈接。
  3. 當用戶點擊郵件正文中的鏈接時,我需要打開一個網頁,在加載時我需要驗證該鏈接是否與該用戶具有相同的鏈接。
  4. 如果是,則以重置密碼的形式加載頁面,否則顯示一些無效消息。

在上面的過程中,我只想要一個代碼發送user_id和唯一的代碼鏈接,並在ASP.net c#中加載鏈接頁時檢測它。

我用GUID創建獨特的鏈接併成功發送郵件。加載鏈接頁面時,我無法驗證用戶。 這裏是我的代碼:

protected void btnRECOVER_PASSWORD_Click(object sender, EventArgs e) 
     { 
      SendMail(); 
     } 

     public void SendMail() 
     { 

      login = new NetworkCredential("[email protected]", "password"); 
      client = new SmtpClient("smtp.1and1.com"); 
      client.Port = Convert.ToInt32(25); 
      client.EnableSsl = true; 
      client.Credentials = login;    
      msg = new MailMessage { From = new MailAddress("[email protected]", "nWorks Employee", Encoding.UTF8) }; 
      msg.To.Add(new MailAddress("[email protected]")); 
      msg.Subject = "Recover Password For Your nWorks Leave Management Account"; 
      msg.CC.Add(new MailAddress("[email protected]")); 
      //  msg.CC.Add(new MailAddress("*************user mail id*************")); 
      string strBody = string.Empty; 
      Guid code = Guid.NewGuid(); 

       strBody += "<html><head></head><body><p>Click the following link to recover your password.</p>"; 
       strBody += Environment.NewLine; 


       strBody += "<form action='' method='POST' name='myForm1'><a href='http://localhost:19343/LoginForm.aspx'>'" + code.ToString() + "'</form><br>"; 



      strBody += "<br/>Thanks.</body></html>"; 

      msg.Body = strBody; 

      msg.BodyEncoding = Encoding.UTF8; 
      msg.IsBodyHtml = true; 
      msg.Priority = MailPriority.Normal; 
      msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; 
      client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); 
      string userstate = "sending......."; 
      client.SendAsync(msg, userstate); 

      string q1 = "insert into RecoverPwdStatus values(101,'" + code.ToString() + "');"; 
      MySqlCommand cmd1 = new MySqlCommand(q1, conn); conn.Open(); 
      MySqlDataReader rdr1 = cmd1.ExecuteReader(); conn.Close(); 

     } 
+0

我使用GUID創建唯一鏈接併成功發送郵件。加載鏈接頁面時,我無法驗證用戶。 – Dipak

+0

難道你不能只發送一個電子郵件地址作爲參數? – christiandev

+0

但是我必須使鏈接一次使用,所以我會把它放在整個用戶的數據庫中,並在用戶點擊鏈接時刪除。如果用戶下次點擊同一鏈接,我會檢查數據庫中是否存在該鏈接,我將允許他重置密碼,否則將顯示您已使用相同鏈接重置密碼。用戶將不能使用一個鏈接重新設置密碼超過一次。 – Dipak

回答

0

使用下面的建立連結的:

<a href='http://localhost:19343/ResetPasswordForm.aspx?guid="+code.ToString()+"&userid="+getUser()+"'> 

訪問這些參數在加載頁面的鏈接,做任何你想要與他們...

string v = Request.QueryString["guid"]; 
      string v1 = Request.QueryString["userid"];