我在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);
}
答案 0 :(得分:2)
您生成的网址中存在错误;
ActivateUser.aspx? userName{0}&Id={1}
...缺少'userName'和'levent'之间的等号。