如何处理Microsoft.aspnetcore.identity的特定错误,在使用密码创建用户时返回?
如何处理特定错误(Microsoft.aspnetcore.inderity.IdentityError
)在创建用户期间通过(usermanager< tuser< tuser>
)类返回。例如,如果错误是:password tooshort或passwandRequiresnonalphanumeric
,我想做一些事情。现在,我获得了有关错误的信息,但是IDK如何处理它们。
我不想做之类的事情,如果(IndentityError ==“错误的名称” {do doys})
,我正在寻找更智能的解决方案...我浏览了很多主题,但找不到我的问题的答案,如果您知道一个问题,请重定向我...
编辑:我做了这样的事情:
if (createResult.Errors.Any(x => x.Code == "PasswordTooShort"))
{
var errorContent = "kielbaska";
return RedirectToAction("ShowError", new ErrorFM
{
ErrorContent = errorContent
});
}
但是我想从括号中替换错误名称,并从可用的列表中替换错误名称结果失败错误,例如类似usrmanager.errordescriber.passwordtooshort
(Just and and示例)
How to handle specific error (Microsoft.AspNetCore.Identity.IdentityError
) returned during creating user by using (UserManager<TUser>
)class. For example, I want to do something if the error is: PasswordTooShort or PasswordRequiresNonAlphanumeric
. Now I get information about errors but idk how to handle them.
I don't want to do something like if(IdentityError == "name of error" {do something})
, I'm looking for smarter solution... I looked through a lot of topics but cannot find an answer to my question, if you know one, please redirect me...
EDIT: I made something like this:
if (createResult.Errors.Any(x => x.Code == "PasswordTooShort"))
{
var errorContent = "kielbaska";
return RedirectToAction("ShowError", new ErrorFM
{
ErrorContent = errorContent
});
}
But I want to replace error name from brackets with error name from list of available result failed errors, for example something like thisusrManager.ErrorDescriber.PasswordTooShort
(just and example)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为Usermanager返回身份证,并且具有身份错误
您必须创建一个像MyResult这样的新类,并在其构造函数中获得IdentityResult:
在您的控制器操作或服务功能中,您必须返回MyResult类
,然后在视图/组件中使用此代码:
1-定义错误变体:
2-在剃须刀代码中使用以下方式:
because UserManager returns IdentityResult , and it has an IEnumrable of Identity Errors
you have to create a new class like Myresult, and get an IdentityResult in its constructor:
and in your controller action or service function, you have to return MyResult class
then, in View/component, use this code:
1- define Error variant:
2- in razor codes use this: