mardi 21 juillet 2015

Is it possible to encript property with custom attribute?

I have a application that I'm updating and I don't wan't to pass the ssn to the screen unless it is being edited by a user that has the rights to see the full ssn.

Who would I code something like this?

ex.

public class person
{
   [encript]
   public string ssn {get; set;}
}

public encriptAttribute: Attribute
{
   encrypt()
   {
     //Not sure what code goes here to 
   }
}

Only other way I can think to do this is maybe custom html helpers but it seems like it would be better to do this at the model level.

Also, I already have some code start to do the encryption. I just don't know how I get/modify a properties value. I know there should be a way as CompareAttribute, MaxLenghtAttribute etc have to see the value in order to work. Also, they work not only on the view by applying corresponding html attributes but on the server as you can validate base of data annotations.

Please provide constructive comments. I have read some of the other post. I'm looking for help because I don't know and haven't found anything that fits my situation saying I can or cant and why.





Aucun commentaire:

Enregistrer un commentaire