Save additional profile data during “Register” in ASP.Net Identity (MVC)

后端 未结 1 1683
清歌不尽
清歌不尽 2021-01-29 12:25

I need to store additional information during user registration such as: First Name, Last Name and etc.

My question has two parts:

  1. How can I save my additi
相关标签:
1条回答
  • 2021-01-29 13:06

    Since your question has two parts:

    1. Your method for storing additional information is correct
    2. You can't proceed unless you see the actual error, in order to see the details you need to add this where you create the user.

      public override int SaveChanges()
      {
          try
          {
              return base.SaveChanges();
          }
          catch (DbEntityValidationException ex)
          {
              // Retrieve the error messages as a list of strings.
              var errorMessages = ex.EntityValidationErrors
                      .SelectMany(x => x.ValidationErrors)
                      .Select(x => x.ErrorMessage);
      
              // Join the list to a single string.
              var fullErrorMessage = string.Join("; ", errorMessages);
      
              // Combine the original exception message with the new one.
              var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
      
              // Throw a new DbEntityValidationException with the improved exception message.
              throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
          }
      }
      
    0 讨论(0)
提交回复
热议问题