PreRegistrationHandler 没有因任务错误代码而失败

PreRegistrationHandler not failing on Task error code

我正在尝试通过 PreRegistrationHandler 对自定义数据属性实施验证。这在通过验证时效果很好。

但是,如果没有,它仍然会创建帐户。当验证未通过时,我 return 一个应该使其失败的任务结果代码。

PreRegistrationHandler = (context, cancellationToken) =>
        {
            var passesvalidation = DoesPassValidation(context); // evals to false
            if (!passesvalidation)
            {
                return Task.FromResult(1); //should fail and not create account, but does anyway
            }
            return Task.FromResult(0); // passes
        }

是否有我应该使用的未记录的 return 代码?我在这里检查过:https://docs.stormpath.com/dotnet/aspnet/latest/registration.html#pre-registration-handler

此功能从 Stormpath ASP.NET 插件的 version 0.9.0 开始工作。

PreRegistrationHandler 中验证失败的语法是:

PreRegistrationHandler = (context, cancellationToken) =>
{
    var passesvalidation = DoesPassValidation(context); // evals to false
    if (!passesvalidation)
    {
        context.Result = new PreRegistrationResult()
        {
            Success = false,
            ErrorMessage = "No way, José!" // optional validation message
        };

        return Task.FromResult(1); // returned value doesn't matter
    }

    return Task.FromResult(0); // without setting context.Result, success is assumed
}