本文整理汇总了C#中Microsoft.AspNetCore.Identity.IdentityResult类的典型用法代码示例。如果您正苦于以下问题:C# IdentityResult类的具体用法?C# IdentityResult怎么用?C# IdentityResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdentityResult类属于Microsoft.AspNetCore.Identity命名空间,在下文中一共展示了IdentityResult类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddErrors
private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
}
示例2: AddIdentityErrors
public static void AddIdentityErrors(this ModelStateDictionary modelState, IdentityResult result)
{
foreach (var error in result.Errors)
{
modelState.AddModelError(string.Empty, error.Description);
}
}
示例3: Failed
/// <summary>
/// Creates an <see cref="IdentityResult"/> indicating a failed identity operation, with a list of <paramref name="errors"/> if applicable.
/// </summary>
/// <param name="errors">An optional array of <see cref="IdentityError"/>s which caused the operation to fail.</param>
/// <returns>An <see cref="IdentityResult"/> indicating a failed identity operation, with a list of <paramref name="errors"/> if applicable.</returns>
public static IdentityResult Failed(params IdentityError[] errors)
{
var result = new IdentityResult { Succeeded = false };
if (errors != null)
{
result._errors.AddRange(errors);
}
return result;
}
示例4: AddErrors
private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error.Description);
_logger.LogWarning("Error in creating user: {error}", error.Description);
}
}
示例5: CheckResult
private IActionResult CheckResult(IdentityResult result)
{
if (result == null)
{
// No error code
return BadRequest();
}
if (!result.Succeeded)
{
var errors = result.Errors.Select(x => this.TransformError(x.Code));
var error = new ErrorResponse(errors.First().Item1, errors.First().Item2.ToString());
error.Parameter_Errors = errors
.GroupBy(x => x.Item1, x => x.Item2)
.ToDictionary(x => x.Key, x => x.Select(y => y.ToString())
.ToArray());
return this.BadRequest(error);
}
return this.Ok();
}
示例6: GetErrorResult
//.........这里部分代码省略.........
// }
// if (_signInManager != null)
// {
// _signInManager.Dispose();
// _signInManager = null;
// }
// }
// base.Dispose(disposing);
// }
// #region Helpers
// // Used for XSRF protection when adding external logins
// private const string XsrfKey = "XsrfId";
// private IAuthenticationManager AuthenticationManager
// {
// get
// {
// return HttpContext.GetOwinContext().Authentication;
// }
// }
// private void AddErrors(IdentityResult result)
// {
// foreach (var error in result.Errors)
// {
// ModelState.AddModelError("", error);
// }
// }
// private ActionResult RedirectToLocal(string returnUrl)
// {
// if (Url.IsLocalUrl(returnUrl))
// {
// return Redirect(returnUrl);
// }
// return RedirectToAction("Index", "Home");
// }
// internal class ChallengeResult : HttpUnauthorizedResult
// {
// public ChallengeResult(string provider, string redirectUri)
// : this(provider, redirectUri, null)
// {
// }
// public ChallengeResult(string provider, string redirectUri, string userId)
// {
// LoginProvider = provider;
// RedirectUri = redirectUri;
// UserId = userId;
// }
// public string LoginProvider { get; set; }
// public string RedirectUri { get; set; }
// public string UserId { get; set; }
// public override void ExecuteResult(ControllerContext context)
// {
// var properties = new AuthenticationProperties { RedirectUri = RedirectUri };
// if (UserId != null)
// {
// properties.Dictionary[XsrfKey] = UserId;
// }
// context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
// }
// }
#region Helpers
private IActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
// return InternalS();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error.Code);
}
}
if (ModelState.IsValid)
{
// No ModelState errors are available to send, so just return an empty BadRequest.
return BadRequest();
}
return BadRequest(ModelState);
}
return null;
}
示例7: AddErrors
private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error);
}
}