当我确认我的邮件地址时,我发现了这个错误: - 一个或多个实体的验证失败。有关详细信息,请参阅'entityvalidationerrors'属性。 [英] I am geting this error while I am confirming my mail address :- validation failed for one or more entities. See 'entityvalidationerrors' property for more details.
本文介绍了当我确认我的邮件地址时,我发现了这个错误: - 一个或多个实体的验证失败。有关详细信息,请参阅'entityvalidationerrors'属性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从我的邮件确认我的邮件地址时,我收到此错误
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
这里是我的regstraion控制器: -
here is my controller of regstraion:-
// 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;
}
}
这是我的注册表
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);
我尝试了什么:
i尝试通过try catch选项但是我没有得到我错的地方
What I have tried:
i tried through try catch option but i am not getting exectly where i am wrong
推荐答案
你应该谷歌它。那里有大量资源。
如何调试一个或多个带图像的实体的验证失败。
对一个或多个实体的验证失败:MVC / Entity Framework 5.0 [ ^ ]
一个或多个实体的验证失败。有关更多详细信息,请参阅EntityValidationErrors属性。 ~DotnetPiper [ ^ ]
请参阅System.Data.Entity.Validation.DbEntityValidationException详细信息 - Musthaan [ ^ ]
补充阅读。 />
如何解决验证问题使用实体框架工作在db中插入代码时,一个或多个实体失败 [ ^ ]
You should Google it. There are tons of resources out there.
How to debug Validation failed for one or more entities with images.
Validation Failed For One or More Entities: MVC/Entity Framework 5.0[^]
Validation failed for one or more entities. See EntityValidationErrors property for more details. ~ DotnetPiper[^]
See System.Data.Entity.Validation.DbEntityValidationException Details – Musthaan[^]
Additional reading.
How to resolve validation fail for one or more entities in inserting code in db using entity frame work[^]
这篇关于当我确认我的邮件地址时,我发现了这个错误: - 一个或多个实体的验证失败。有关详细信息,请参阅'entityvalidationerrors'属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文