locked
Membership.GetUserNameByEmail(txtUserName.Text.Trim()) == null RRS feed

  • Question

  • User-1651858287 posted
                if (!string.IsNullOrEmpty(txtUserName.Text.Trim()))
                {
                    Lostuser = Membership.GetUserNameByEmail(txtUserName.Text.Trim());
                    try
                    {
                        if (!string.IsNullOrEmpty(Lostuser))//getting null 
                        {
                            MembershipUser mu = Membership.GetUser(Lostuser);
                            NewPassword = mu.ResetPassword();
                            SendEmail();
                            //  Response.Write(NewPassword);
                            //  EmailPassword(password, mu.Email);
                            Session["help"] = "Please check your email for your new password.";
    
    
                            Response.Redirect("~/help.aspx");
                        }
                        else
                        {
    
    
    
    
                            Session["help"] = "Unfortunately your Email Address is not Registered in our Database";
    
    
                            Response.Redirect("~/help.aspx");
                          
                        }
                    }
                    catch (Exception exp)
                    {
                        Response.Write("Your password is lock Please contact the Administrator ICT Center" + exp.Message);
                    }
                }
    I want to send the user an email with a new password.
    but I am getting null even if the user is in the database

    Monday, March 8, 2021 8:52 PM

Answers

  • User-939850651 posted

    Hi sweetSteal,

    sweetSteal

    Lostuser = Membership.GetUserNameByEmail(txtUserName.Text.Trim());

    According to the code you provided, I found that its Membership.GetUserNameByEmail(String) Method uses email addresses to match data. If there is no matching value, it returns null, which is consistent with the description in the document. 

    Although you have mentioned that the user information already exists in the data sheet, I still have doubts about this point.

    By the way, this method trims the leading and trailing spaces of the parameters, so you don't need to format the data manually.

    If you are sure that the error mentioned above does not exist, then I think your problem may be a configuration problem (the wrong data source may be configured). Please check them.

    For more details, you could refer to this document:

    Configuring an ASP.NET Application to Use Membership

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 9, 2021 2:55 AM

All replies

  • User-939850651 posted

    Hi sweetSteal,

    sweetSteal

    Lostuser = Membership.GetUserNameByEmail(txtUserName.Text.Trim());

    According to the code you provided, I found that its Membership.GetUserNameByEmail(String) Method uses email addresses to match data. If there is no matching value, it returns null, which is consistent with the description in the document. 

    Although you have mentioned that the user information already exists in the data sheet, I still have doubts about this point.

    By the way, this method trims the leading and trailing spaces of the parameters, so you don't need to format the data manually.

    If you are sure that the error mentioned above does not exist, then I think your problem may be a configuration problem (the wrong data source may be configured). Please check them.

    For more details, you could refer to this document:

    Configuring an ASP.NET Application to Use Membership

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 9, 2021 2:55 AM
  • User-1651858287 posted

    I am not sure what happened. I need a system restart and the code starting working again. 

    I am not sure why but that was strange?

    thanks.

    Tuesday, March 9, 2021 7:24 AM