I am using data annotations to validate an emailaddress.
To show an error message when the emailaddress is not valid, I use a RESX file called ErrorMessages.
My code is like this:
public class EmailAdressAttribute : RegularExpressionAttribute
{
public EmailAdressAttribute()
: base(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,3}|[0-9]{1,4})(\]?)$")
{
ErrorMessage = ErrorMessages.ValidateEmailAdress;
}
When I change to language (current culture) of my asp.net mvc application while running the application, the old language is still shown.
After debugging I found out that the constructor for this attribute is only called once(when I use it for the first time ).
How is the attribute being cached ? How can I show the correct error message from the resource file?