[英]Duplicating users if clicking multiple times in ASP.NET (webforms) / OWIN
I'm creating a user using OWIN.我正在使用 OWIN 创建一个用户。 Problem is, while creating an account... I manually check in my database if the user already exists.
问题是,在创建帐户时...如果用户已经存在,我会手动检查我的数据库。 What is happening quite frequently is, if a user double, triple, or even more clicks it displays them with the "your account has already been made" error, and doesn't automatically redirect them.
经常发生的是,如果用户两次、三次甚至更多次点击,它会显示“您的帐户已经创建”错误,并且不会自动重定向它们。 Furthermore, it creates loads of duplicates of the data I'm saving to another table in SQL which is used for new users signing up.
此外,它会创建大量重复的数据,我正在保存到 SQL 中的另一个表中,该表用于新用户注册。
This is the code that gets executed when the user clicks这是用户点击时执行的代码
if (!u.userExists(email))
{
var created = um.CreateUser(email, email, password, firstName, lastName, country, ip);
if (created == true)
{
u.subscribeSIB(email, firstName, lastName, country);
Response.RedirectPermanent("/members/");
}
else
{
ipTop.Text = "<span class=\"text-danger mt-3\">An Error Occured</span>";
}
}
else // acc exists
{
ipTop.Text = "<span class=\"text-danger mt-3\">Sorry - it seems you've already made an account before. <a href=\"/login\">Sign In</a>.</span>";
}
And this is the code that checks if the user exists这是检查用户是否存在的代码
public bool userExists(string email)
{
var userStore = new UserStore<IdentityUser>();
var userManager = new UserManager<IdentityUser>(userStore);
var useremail = userManager.FindByEmail(email);
if (useremail == null)
{
return false;
}
return true;
}
How should I go about stopping the duplicates, and the multiple triggering?我应该如何停止重复和多次触发?
<asp:Button ID="MyButton" runat="server" CssClass="button" Text="Click Here" OnClientClick="$('.button').hide();" OnClick="MyButton_Click" />
You can do the above, using jquery.您可以使用 jquery 执行上述操作。 The OnClientClick will hide the button on the client side, and then the postback will proceed to the server.
OnClientClick 将隐藏客户端的按钮,然后回发将继续到服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.