Reputation: 3648
I have made a custom attribute which checks the password complexity, the issue is that it called when i first run the code, after that if i change the complexity it does not register that attribute even if the session is refreshed.
i am calling it on property named password in UserModel.
[ComplexPassword()]
public String Password { get; set; }
The custom attribute is here.
public class ComplexPassword : RegularExpressionAttribute
{
public ComplexPassword()
: base(GetRegex())
{
T = Localizer.CaptionInstance;
}
private Localizer.CaptionDelegate T { get; set; }
Some Logic here...
}
the Password property is used in the changed password form which is using user model. i think view code is not necessary to show. Can anyone guide how to fire it at every at every call of Password property.
Upvotes: 0
Views: 576
Reputation: 3540
I believe the Data Annotations get cached on a model. So if you are doing something behind the scenes so that GetRegex() changes depending on something you do in the app, it might not be reflected in any new validation attempts on the model. You might need to create your own MetadataProvider that cusotmizes the behavior of DataAnnotationsModelMetadataProvider
Upvotes: 1