I'm new to ASP.NET Core and I'm creating a project for which I need a database to store the users inside.
I've put an unique index on my Username (Nom) and E-mail (Mail) fields when I build the database in my context :
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Utilisateur>().HasIndex(u => u.Nom).IsUnique();
modelBuilder.Entity<Utilisateur>().HasIndex(u => u.Mail).IsUnique();
modelBuilder.Entity<Utilisateur>().ToTable("tblUtilisateur");
}
Here is the Utilisateur class:
using System.ComponentModel.DataAnnotations;
namespace Clavardage.Models
{
public class Utilisateur
{
public string Pseudo { get; set; }
[Required]
public string Nom { get; set; }
[Required]
[MinLength(6)]
public string Mdp { get; set; }
[Required]
public string Mail { get; set; }
}
}
At this point my fields are actually unique but when I enter a non-unique username or e-mail I get this error page :
Is there a way to just send a message to the user as ASP.NET Core does on it's own for [Required] or [MinLength(6)] with the asp-valifation-for tag?

