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.");
}