MongoDB C# - Hide property from serializer

Posted by ehftwelve on Stack Overflow See other posts from Stack Overflow or by ehftwelve
Published on 2012-09-11T15:31:12Z Indexed on 2012/09/11 15:38 UTC
Read the original article Hit count: 228

Filed under:
|

This is what my user model looks like:

namespace Api.Models
{
    public class User
    {

        [BsonId(IdGenerator = typeof(StringObjectIdGenerator))]
        [BsonRequired]
        public string Id { get; set; }

        [Required(ErrorMessage = "Username is required.")]
        [StringLength(20, MinimumLength=3, ErrorMessage="Username must be between 3 and 20 characters.")]
        [BsonRequired]
        public string Username { get; set; }

        [Required(ErrorMessage="Email is required.")]
        [EmailAddress(ErrorMessage="Valid email required.")]
        [BsonRequired]
        public string Email { get; set; }

        [Required(ErrorMessage = "Password is required.")]
        [StringLength(50, MinimumLength=8, ErrorMessage="Password must be between 8 and 50 characters.")]
        [BsonRequired]
        public string Password { get; set; }

        [BsonRequired]
        public string Salt { get; set; }

    }
}

I want to write, and require, all of the properties into the MongoDB Database. What I don't want to do, is expose the Password and Salt properties when I send this through the request.

Is there any sort of data attribute that I can set that will write it, but not expose it when displayed to any API user?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about mongodb-csharp