System.Data.SqlClient.SqlException:无效的列名称'Email'

时间:2013-05-01 18:44:29

标签: asp.net-mvc-4 simplemembership

我正在开发一个新的ASP.Net MVC 4应用程序并测试用户登录。我得到以下例外:

System.Data.SqlClient.SqlException: Invalid column name 'Email'

我正在使用http://kevin-junghans.blogspot.com/2013/02/adding-email-confirmation-to.html中的示例。

以下是适当的代码:

[AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    string confirmationToken =
                        WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email }, true);

                    System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress("noreply@cardmage.com");
                    System.Net.Mail.MailAddress[] to = new System.Net.Mail.MailAddress[1];
                    to[1] = new System.Net.Mail.MailAddress(model.Email);
                    System.Net.Mail.MailAddress[] cc = new System.Net.Mail.MailAddress[0];
                    System.Net.Mail.MailAddress[] bcc = new System.Net.Mail.MailAddress[0];
                    String Subject = "Please verify your e-mail address.";
                    String body = String.Format("Thank you for registering with CardMage." +
                        "To verify your account, please follow this link." +
                        "http://www.cardmage.co/Account/RegisterConfirmation/{0}", confirmationToken);
                    System.Net.NetworkCredential nc = new NetworkCredential("foo", "bar");
                    SendGrid sg = SendGrid.GetInstance(from, to, cc, bcc, Subject, body, "");
                    SMTP s = SMTP.GetInstance(nc);
                    s.Deliver(sg);
                    return RedirectToAction("RegisterStepTwo", "Account");

我做错了什么?我试图从谷歌搜索中找到解决方案,但没有运气。我发现this SO问题的属性值格式与我相同,所以我检查了我的数据库,但是电子邮件列不存在。有人可以指点我正确的方向吗?感谢您的时间和考虑。

1 个答案:

答案 0 :(得分:3)

要通过调用CreateUserAndAccount更新您的电子邮件字段,请执行以下操作:

1确保您使用的数据库表具有电子邮件列。

2更改帐户模型UserProfile以包含您的电子邮件字段。

3更改“注册”视图以包含您的电子邮件。

4更改AccountController以包含一个不对称的对象(这是你已经完成的)

然后,当您注册新用户时,他们的电子邮件将存储在数据库表中。

这适合我。

相关问题