我正在研究一個新的ASP.Net MVC 4應用程序並測試用戶登錄。我收到以下異常:System.Data.SqlClient.SqlException:無效的列名'Email'
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("[email protected]");
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問題的屬性值格式與我一樣,所以我檢查了我的數據庫,但Email列不存在。有人可以請指點我正確的方向嗎?感謝您的時間和考慮。
我假設你在調用CreateUserAndAccount時遇到了錯誤,並且如果你查看數據庫,Table UserProfile沒有Email列。請提供UserProfile類定義的代碼,數據庫初始值設定項和Global.asax Application_Start方法。請注意,本文假定您遵循上一篇文章中關於自定義和種植SimpleMembership的步驟。 http://kevin-junghans.blogspot.com/2013/01/seeding-customizing-aspnet-mvc.html – 2013-05-01 19:10:56