Put Asp Net MVC Identity validation

Asked

Viewed 269 times

-2

I tried to locate this doubt in the forum and could not find. I have an Asp Net MVC application that uses the Entity Framework with Identity to login. My client registration works perfectly, but I’m not able to validate two fields: Username and Login. I tried to locate where they are called, but from what I read on the net so far, it gets "encapsulated" and I couldn’t put the validations on them. I’d like to put a validation like that on them:

[Required]
    [StringLength(10, MinimumLength = 6)]
    public string Senha { get; set; }

The problem is that I am not able to find Username and Login. I could not find the Accountviewmodels.Cs that I was referred to on the net. Can someone please help me? I would just like to validate the Username and Login fields so that it is not possible to save the registration with them blank, as I did not find their location, I can not validate and the easiest way I found was as I reported in the code above.

  • if you save it surely is passing the value to them in your action ... just give an F12 on top of the class.

1 answer

0

To register a user, Identity in aspnet mvc 5 uses the class Registerviewmodel that’s in the archive Accountviewmodels.Cs inside the briefcase Models.

public class RegisterViewModel
{
    [Required]
    [EmailAddress]
    [Display(Name = "Email")]
    public string Email { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}

This is the class gets the email, password and password confirmation from the registration screen. Here you can customize the validations at will.

  • I tried to find this Accountviewmodels.Cs file in my project in the Models folder and could not find it. Do you know if it has another name? I searched the whole project here and did not find this Model file nor the Registerviewmodel class

  • Which version of . net are you using? Using the Identity you have in the template?

  • would that be the version, right? <package id="Microsoft.AspNet.Identity.Entityframework" version="2.2.1" targetFramework="net451" />

  • It’s weird not having these files. You can upload a screenshot of the model and controller folders of your project to see how this?

  • upload the folder image here https://uploaddeimagens.com.br/imagens/pastas-jpg-3

  • For your files you are not using the Identity that comes in the aspnet mvc 5 template. You have implemented your own login system?

  • This actually followed a course that taught to do this login system. The course has already ended and I saw that there are some outstanding points, such as these validations and I am no longer able to contact them.

  • So to answer your question you would have to have access to your user registration code (controller and viewmodel) in order to help you. Using the standard aspnet mvc Identity the answer is the one I even gave.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.