场景是,如果用户第一次使用他的一次性密码登录,它应该被重定向到 ResetPassword.aspx
如果用户不是新用户,则应重定向到 Main.aspx 页面。
我应该使用 IsPostBack
还是 Membership.ValidateUser
?
我们通常如何在 C# 中编写代码来检查它是否是新用户(使用首次登录)?
我是编程新手,在网上没有获得足够的信息。请帮忙
最佳答案
IsPostBack
检查不会帮助您完成您想要的。你需要通过数据库来维护它。
IsPostBack Gets a value that indicates whether the page is being rendered
for the first time or is being loaded in response to a postback.
它与页面发布有关,与您的数据库或您的用户或您的逻辑无关:)
为了帮助您理解您的逻辑,您需要维护一个单独的列来标识用户是否是第一次来。
一个简单的逻辑:
在您的表格中创建一列,例如 LastLoginDate
使其可为空。当用户注册时,将此字段保留为 NULL。
当用户登录时,只需检查 LastLoginDate
是否为 NULL 即
if(userObj.LastLoginDate == null)
{
//user has come for the first time
//code to update the LastLoginDate to DateTime.Now
Redirect("resetPassword.aspx");
}
else
{
//code to update the LastLoginDate to DateTime.Now
Redirect("home.aspx");
}
关于c# - 如何查找用户是否是第一次登录 - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15632447/