when i am confirming my mail address from my mail i am getting this error
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Source Error:
Line 130: {
Line 131: user.ConfirmedEmail = true;
Line 132: await UserManager.UpdateAsync(user);
Line 133: await SignInAsync(user, isPersistent: false);
Line 134: return RedirectToAction("Index", "Home", new { ConfirmedEmail = user.Email });
Source File: G:\myebpassproject\ebpassprojects\ebpassprojects\Controllers\AccountController.cs Line: 132
here is my controller of regstraion:-
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
try
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, Gender = model.Gender, DOB = model.DOB, Profile = model.Profile, Mobile = model.Mobile, Address = model.Address, City = model.City, State = model.State };
user.ConfirmedEmail = false;
var result = await UserManager.CreateAsync(user, model.Password);
using (ApplicationDbContext db = new ApplicationDbContext())
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress("my mail id", "Web Registration"),
new System.Net.Mail.MailAddress(user.Email));
m.Subject = "Email confirmation";
m.Body = string.Format("Dear {0}<BR/>Thank you for your registration, please click on the below link to complete your registration: <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>", user.UserName, Url.Action("ConfirmEmail", "Account", new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));
m.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp-mail.outlook.com");
smtp.Credentials = new System.Net.NetworkCredential("my mail id", "my password");
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.Send(m);
return RedirectToAction("Confirm", "Account", new { Email = user.Email });
}
AddErrors(result);
}
return View(model);
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
{
Exception raise = dbEx;
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
string message = string.Format("{0}:{1}",
validationErrors.Entry.Entity.ToString(),
validationError.ErrorMessage);
raise = new InvalidOperationException(message, raise);
}
}
throw raise;
}
}
here is my registration table
CREATE TABLE [dbo].[AspNetUsers] (
[Id] NVARCHAR (128) NOT NULL,
[Email] NVARCHAR (256) NULL,
[EmailConfirmed] BIT NOT NULL,
[PasswordHash] NVARCHAR (MAX) NULL,
[SecurityStamp] NVARCHAR (MAX) NULL,
[PhoneNumber] NVARCHAR (MAX) NULL,
[PhoneNumberConfirmed] BIT NOT NULL,
[TwoFactorEnabled] BIT NOT NULL,
[LockoutEndDateUtc] DATETIME NULL,
[LockoutEnabled] BIT NOT NULL,
[AccessFailedCount] INT NOT NULL,
[UserName] NVARCHAR (256) NOT NULL,
[FirstName] NVARCHAR (MAX) NULL,
[MiddleName] NVARCHAR (MAX) DEFAULT ('') NOT NULL,
[LastName] NVARCHAR (MAX) DEFAULT ('') NOT NULL,
[Gender] NVARCHAR (MAX) DEFAULT ('') NOT NULL,
[DOB] NVARCHAR (MAX) DEFAULT ('') NOT NULL,
[Profile] NVARCHAR (MAX) NULL,
[Mobile] DECIMAL (18, 2) DEFAULT ((0)) NOT NULL,
[Address] NVARCHAR (MAX) DEFAULT ('') NOT NULL,
[City] NVARCHAR (MAX) DEFAULT ('') NOT NULL,
[State] NVARCHAR (MAX) DEFAULT ('') NOT NULL,
[ConfirmedEmail] BIT DEFAULT ((0)) NOT NULL,
CONSTRAINT [PK_dbo.AspNetUsers] PRIMARY KEY CLUSTERED ([Id] ASC)
);
GO
CREATE UNIQUE NONCLUSTERED INDEX [UserNameIndex]
ON [dbo].[AspNetUsers]([UserName] ASC);
What I have tried:
i tried through try catch option but i am not getting exectly where i am wrong