How to change error message in ASP.NET Identity -
i have 1 question. i'm trying change error message in identity asp .net , don't know how it. want change error message - "login taken". createasync method return error message. please me.
the microsoft.aspnet.identity.usermanager<tuser>
class has public property called uservalidator
of type iidentityvalidator<tuser>
. constructor usermanager sets property instance of microsoft.aspnet.identity.uservalidator<tuser>
. error messages see when calling createasync come resources embedded in microsoft.aspnet.identity.dll , added identityresult inside uservalidator.
you provide own implementation of iidentityvalidator<tuser>
, single method signature: task<identityresult> validateasync(tuser item)
. you'd have implement own validations, you'd have control on messages come out. like:
public class uservalidator : iidentityvalidator<applicationuser> { public async task<identityresult> validateasync(applicationuser item) { if (string.isnullorwhitespace(item.username)) { return identityresult.failed("really?!"); } return identityresult.success; } }
the default uservalidator class performs 3 basic validations keep in mind if roll own:
- username not null or whitespace
- username alphanumeric
- username not duplicate
Comments
Post a Comment