如何更改MVC Core ValidationSummary的默认错误消息?

AG7*_*G70 8 asp.net-mvc asp.net-identity asp.net-core

将MVC Core与ASP.NET Identity一起使用我想更改从Register操作到达的ValidationSummary的默认错误消息.任何建议将不胜感激.

ASP.NET核心注册操作

ade*_*lin 16

您应该覆盖IdentityErrorDescriber更改身份错误消息的方法.

public class YourIdentityErrorDescriber : IdentityErrorDescriber
{
    public override IdentityError PasswordRequiresUpper() 
    { 
       return new IdentityError 
       { 
           Code = nameof(PasswordRequiresUpper),
           Description = "<your error message>"
       }; 
    }
    //... other methods
}
Run Code Online (Sandbox Code Playgroud)

Startup.cs集合中IdentityErrorDescriber

public void ConfigureServices(IServiceCollection services)
{
    // ...   
    services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddErrorDescriber<YourIdentityErrorDescriber>();
}
Run Code Online (Sandbox Code Playgroud)

答案来自/sf/answers/2673992331/