如何在电子邮件激活链接中传递我的值

本文关键字:我的 链接 电子邮件 激活 | 更新日期: 2023-09-27 18:28:50

我在deneme.aspx中写了一些代码,它可以工作,但它没有将变量(Id(levent)和userName(levent))传递给activateUser.aspx。我该怎么做?

        SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
        var mail = new MailMessage();
        mail.From = new MailAddress("bilkentliaslan@windowslive.com");
        mail.To.Add("levent_kalay@hotmail.com");
        mail.Subject = "Test Mail - 1";
        mail.IsBodyHtml = true;
        string htmlBody;
        htmlBody = string.Format("<a href='http://localhost:15534/ActivateUser.aspx?userName{0}&Id={1}'>Activate {0} </a>", "levent", "levent");
        mail.Body = htmlBody;
        SmtpServer.Port = 587;
        SmtpServer.UseDefaultCredentials = false;
        SmtpServer.Credentials = new System.Net.NetworkCredential("bilkentliaslan@windowslive.com", "mypassword");
        SmtpServer.EnableSsl = true;
        SmtpServer.Send(mail);

然后,点击确认链接后,它会转到中的ActivateUser.aspx

  protected void Page_Load(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(Request.Params["Id"]))
        {
            // We do not have the userId. Redirect some where
            Response.Redirect("login.aspx");
        }
        else
        {
            // We have a userId.
            try
            {
                DBConnection db = new DBConnection();
                string username= Request.Params["userName"];
                bool res =     db.CheckLogin(Request.Params["userName"],Request.Params["Id"]);
                if (res)
                {
                    Session["LetLogin"] = "ok";

                    Session["User_Name"] = Request.Params["userName"];
                    Response.Redirect("WebForm4.aspx",true);
                }

            }
            catch
            {
                // Error. Redirect some where
                Response.Redirect("login.aspx");
            }
        }
        // We should never reach here. Just in case redirect some where
        Response.Redirect("login.aspx", true);
    }

如何在电子邮件激活链接中传递我的值

您生成的URL中有一个错误;

ActivateUser.aspx?    userName{0}&Id={1}

在"userName"answers"levent"之间缺少等号。

相关文章: