0

I am trying to add two fields to my UserPofile table in WebMatrix. Everytime I run the code I get this message: Account creation was unsuccessful. Please correct the errors and try again. The username is already in use.

But, when I look in the table I don't see the new fields.

Here is my code:

if (Validation.IsValid()) {
        var db = Database.Open("StarterSite");

        var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", email);

        if (user == null) {                      
            db.Execute("INSERT INTO UserProfile (Email) VALUES (@0)", email);

          try {
                bool requireEmailConfirmation = !WebMail.SmtpServer.IsEmpty();
               <!-- var token = WebSecurity.CreateAccount(email, password, requireEmailConfirmation);-->
                var token = WebSecurity.CreateUserAndAccount(email, password, new {UserName = name, UserLocation = location}, requireEmailConfirmation);
                if (requireEmailConfirmation) {
                    var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
                    var confirmationUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Confirm?confirmationCode=" + HttpUtility.UrlEncode(token));

                    WebMail.Send(
                        to: email,
                        subject: "Please confirm your account",
                        body: "Your confirmation code is: " + token + ". Visit <a href=\"" + confirmationUrl + "\">" + confirmationUrl + "</a> to activate your account."
                    );
                }

                if (requireEmailConfirmation) {
                    Response.Redirect("~/Account/Thanks");
                } else {                        
                    WebSecurity.Login(email, password);
                    Response.Redirect("~/");
                }
            } catch (System.Web.Security.MembershipCreateUserException e) {
                ModelState.AddFormError(e.Message);
            }
        } else {               
            ModelState.AddFormError("Email address is already in use.");
        }
tereško
  • 58,060
  • 25
  • 98
  • 150
tnlewis
  • 323
  • 1
  • 3
  • 15
  • Are you certain that the error message says the _user name_ is already in use, and not the *email address* is already in use? – Mike Brind Mar 29 '16 at 14:05
  • Yes, I copied and pasted the message. I looked in my app and I don't know where it's coming from. – tnlewis Mar 29 '16 at 14:59

0 Answers0