This is easier to explain with an example. Suppose I have a person class
Public Person
{
string firstName;
string SocialSecurityNumber;
}
When some changes are made by the user in a web page, the Person object is posted back to a controller that accepts Person as the input parameter. The SocialSecurity number is encrypted. We have many pages that post back objects (Not Necessarily Person class) that have encrypted Social security as a parameter. Now I want to modify the model binding, so that if the posted object has SocialSecurityNumber as a property, it should be automatically decrypted. How can I do this?
You could use a custom model binder. Some examples:
This is an example of a simple one I’ve used before that you could modify for your needs:
You could then create an attribute to decorate the property as required:
This is “activated” by an attribute on the property in the ViewModel
It should be fairly simple to modify this to allow for encryption.