C# 使用链接传递一些参数,并在使用c加载链接页面时检测它#
过程:C# 使用链接传递一些参数,并在使用c加载链接页面时检测它#,c#,asp.net,C#,Asp.net,过程: 向特定用户发送电子邮件,邮件正文包含唯一链接 同时,我需要在该用户的数据库中存储该唯一链接 当用户单击邮件正文中的链接时,我需要打开一个网页,并在加载时验证该链接是否与该用户的链接相同 如果是,则加载带有重置密码表单的页面,否则显示一些无效消息 在上面的过程中,我只需要一个代码,用于发送用户id和带有链接的唯一代码,并在ASP.net c#中加载链接页面时检测它 我使用GUID创建唯一链接并成功发送邮件。加载链接页面时,我无法验证用户。 这是我的密码: protected void b
GUID
创建唯一链接并成功发送邮件。加载链接页面时,我无法验证用户。
这是我的密码:
protected void btnRECOVER_PASSWORD_Click(object sender, EventArgs e)
{
SendMail();
}
public void SendMail()
{
login = new NetworkCredential("leaves@nworks.co", "password");
client = new SmtpClient("smtp.1and1.com");
client.Port = Convert.ToInt32(25);
client.EnableSsl = true;
client.Credentials = login;
msg = new MailMessage { From = new MailAddress("leaves@nworks.co", "nWorks Employee", Encoding.UTF8) };
msg.To.Add(new MailAddress("dipak.akhade@nworks.co"));
msg.Subject = "Recover Password For Your nWorks Leave Management Account";
msg.CC.Add(new MailAddress("dipak.a.akhade9192@gmail.com"));
// 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();
}
protectedvoidbtnReceive\u PASSWORD\u单击(对象发送者,事件参数e)
{
SendMail();
}
public void SendMail()
{
登录=新的网络凭据(“leaves@nworks.co“,”密码“);
client=新的SmtpClient(“smtp.1和1.com”);
client.Port=Convert.ToInt32(25);
client.enablesl=true;
client.Credentials=登录;
msg=新邮件{From=新邮件地址(“leaves@nworks.co“,”nWorks Employee“,Encoding.UTF8)};
msg.To.Add(新邮件地址(“dipak。akhade@nworks.co"));
msg.Subject=“恢复您的NWWorks休假管理帐户的密码”;
msg.CC.Add(新邮件地址(“dipak.a。akhade9192@gmail.com"));
//msg.CC.Add(新邮件地址(“*******************用户邮件id****************”);
string strBody=string.Empty;
Guid代码=Guid.NewGuid();
strBody+=“单击以下链接以恢复密码。”;
strBody+=Environment.NewLine;
strBody+=“'”+code.ToString()+“
”;
strBody+=“
谢谢。”;
msg.Body=strBody;
msg.BodyEncoding=Encoding.UTF8;
msg.IsBodyHtml=true;
msg.Priority=MailPriority.Normal;
msg.DeliveryNotificationOptions=DeliveryNotificationOptions.OnFailure;
client.SendCompleted+=新的SendCompletedEventHandler(SendCompletedCallback);
字符串userstate=“发送……”;
sendaync(msg,userstate);
字符串q1=“插入到RecoverPwdStatus值中(101'”+code.ToString()+”;”;
MySqlCommand cmd1=新的MySqlCommand(q1,conn);conn.Open();
MySqlDataReader rdr1=cmd1.ExecuteReader();conn.Close();
}
使用以下内容创建链接:
<a href='http://localhost:19343/ResetPasswordForm.aspx?guid="+code.ToString()+"&userid="+getUser()+"'>
我使用GUID创建唯一链接并成功发送邮件。在加载链接页面时,我无法验证用户。您不能只发送一个电子邮件地址作为参数吗?但我必须使该链接一次性使用,以便我将它放在整个用户的数据库中,并在用户单击该链接时将其删除。若用户下次单击相同的链接,我将检查该链接是否存在于数据库中,我将允许他重置密码,否则将显示您已使用相同的链接重置密码。用户将不能使用一个链接多次重置密码。为此,我们需要识别用户和链接。请显示一些代码。
string v = Request.QueryString["guid"];
string v1 = Request.QueryString["userid"];