2

I have a class - Person. The consumer of the Web API service must set the ID. I don't want them to be able to set or even see the InternalID.

public class Person
{
    [Required(ErrorMessage = "ID is required.")]
    public string ID { get; set; }

    public string InternalID { get; set; }

 }

Other parts of my application will need to work with the InternalID, so setting it private/internal won't work.

tom
  • 1,822
  • 4
  • 25
  • 43
  • See this post http://stackoverflow.com/questions/11851207/prevent-property-from-being-serialized-in-web-api – Lars Anundskås Sep 03 '13 at 20:35
  • That post suggests many approaches and has many links to external articles. Is there one in particular? – tom Sep 03 '13 at 20:42

2 Answers2

4

I just found this and it looks good to me.

    [JsonIgnore]
    [XmlIgnore]
    public string InternalID { get; set; }
tom
  • 1,822
  • 4
  • 25
  • 43
0

Why don't you obfuscate your id? You could have a function crypting the ID to a value and then de-crypting it. So the encrypted ID would be public and the decrypted ID would be private.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175