Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在IdentityServer 4中设置自定义错误消息?_C#_Asp.net Core_Identityserver4_Asp.net Core Identity - Fatal编程技术网

C# 如何在IdentityServer 4中设置自定义错误消息?

C# 如何在IdentityServer 4中设置自定义错误消息?,c#,asp.net-core,identityserver4,asp.net-core-identity,C#,Asp.net Core,Identityserver4,Asp.net Core Identity,我正在尝试自定义IdentityServer 4返回的错误消息。我正在运行.NET Core 2.2应用程序。查看列表,我添加了以下内容: services .AddIdentityServer() // other stuff .AddCustomTokenRequestValidator<TestValidator>(); ... public class TestValidator : ICustomTokenRequestValidator {

我正在尝试自定义IdentityServer 4返回的错误消息。我正在运行.NET Core 2.2应用程序。查看列表,我添加了以下内容:

services
    .AddIdentityServer()
    // other stuff
    .AddCustomTokenRequestValidator<TestValidator>();

...

public class TestValidator : ICustomTokenRequestValidator
{
    public Task ValidateAsync(CustomTokenRequestValidationContextcontext)
    {
        var validationResult = context.Result;

        validationResult.ErrorDescription = ":D";

        return Task.CompletedTask;
    }
}

.Error()
不是上下文中的一种东西吗?我认为您只需返回
任务。成功返回CompletedTask
。客户端id和机密验证在
IClientSecretValidator
中完成,因此您必须实现它。
var token = await httpClient.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest {...});