简体   繁体   English

如果在 ASP.NET (webforms) / OWIN 中多次单击,则复制用户

[英]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.

相关问题 如何防止用户单击ASP.NET Webforms的gridview中多次启动文件下载的图像按钮? - How to prevent a user from clicking an imagebutton that's starting a file download multiple times in a gridview in ASP.NET Webforms? 在ASP.NET WebForms中使用时间 - Using times at asp.net webforms 与Asp.Net WebForms中的Owin Startup类进行IdentityServer4通信 - Communicating with IdentityServer4 with Owin Startup class in Asp.Net WebForms ASP.NET Webform-如何停止多次单击按钮 - ASP.NET Webform - how to stop the clicking of a button multiple times 通过ASP.NET Webforms,OWIN和ASP.NET Identity了解Autofac中间件的使用 - Understanding Autofac middleware usage with ASP.NET Webforms, OWIN and ASP.NET Identity ASP.NET Webforms 多个按钮 - ASP.NET Webforms Multiple Buttons 单击ASP.NET Webforms中的按钮时,空引用异常 - Null Reference Exception when Clicking a button in ASP.NET Webforms 如何通过多次单击按钮多次创建ASP.NET标签 - How to create ASP.NET labels multiple times by clicking a button multiple times ASP.Net WebForms| 仅向登录用户显示文本? - ASP.Net WebForms| Show text only to login users? Asp.net 4.8 WebForms授权使用Owin OpenId Connect Authentication (app.UseOpenIdConnectAuthentication) - Asp.net 4.8 WebForms authorization using Owin OpenId Connect Authentication (app.UseOpenIdConnectAuthentication)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM