1

我正在开发一个新的 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");

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

4

1 回答 1

3

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

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

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

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

4 更改 AccountController 以包含一个匿名对象(您已完成此操作)

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

这对我有用。

于 2013-05-10T07:52:48.927 回答