Я получаю эту ошибку, когда подтверждаю свой почтовый адрес : - проверка не удалась для одного или нескольких объектов. Дополнительные сведения см. В разделе свойство entityvalidationerrors.
когда я подтверждаю свой почтовый адрес с моей почты я получаю эту ошибку
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
вот мой контролер регстрайона:-
// POST: /Account/Register [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 }); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); } AddErrors(result); } // If we got this far, something failed, redisplay form 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 a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
вот мой регистрационный стол
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);
Что я уже пробовал:
я попробовал через опцию try catch, но я не получаю exectly, где я ошибаюсь
Richard Deeming
Поэтому, когда вы отладили свой код и посмотрели на EntityValidationErrors
коллекция, какие ошибки вы видели?
Himanshu.A.Joshi
я не знаю, что это не показывает мне фактическую ошибку.
Richard Deeming
Что ж, вам нужно его найти. Мы не можем сказать вам, в чем проблема, не видя ошибок.