Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.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# 将自定义令牌RequestValidator添加到ASP.NET(非核心)_C#_.net_Identityserver3 - Fatal编程技术网

C# 将自定义令牌RequestValidator添加到ASP.NET(非核心)

C# 将自定义令牌RequestValidator添加到ASP.NET(非核心),c#,.net,identityserver3,C#,.net,Identityserver3,我想用自定义验证器替换默认的请求令牌验证器。用于此的IdentityServer文档表明自定义验证器已在ASP.NET Core Startup.cs ConfigureServices()中注册,但我使用的应用程序是ASP.NET/.NET 4.5 如何在ASP.NET应用程序中注册自定义验证程序 // My understanding is that this how I would add my validator with Core. public void ConfigureServi

我想用自定义验证器替换默认的请求令牌验证器。用于此的IdentityServer文档表明自定义验证器已在ASP.NET Core Startup.cs ConfigureServices()中注册,但我使用的应用程序是ASP.NET/.NET 4.5

如何在ASP.NET应用程序中注册自定义验证程序

// My understanding is that this how I would add my validator with Core.
public void ConfigureServices(IServiceCollection services)
{
    var builder = services.AddIdentityServer()
        .AddCustomTokenRequestValidator<MyCustomRequestValidator>();
}
//我的理解是,这就是我将如何添加带核心的验证器。
public void配置服务(IServiceCollection服务)
{
var builder=services.AddIdentityServer()
.AddCustomTokenRequestValidator();
}

这很容易。在
startup.cs
ConfigureService
中,您可以指定要使用的验证器。我对项目代码使用JWT身份验证,如下所示:

// Jwt Authentication
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
  {
       options.TokenValidationParameters = new TokenValidationParameters
        {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey = new SymmetricSecurityKey(key),
                ValidateIssuer = false,
                ValidateActor = false,
        };
   });
注意:对于这段代码,我使用了库

使用Microsoft.AspNetCore.Authentication.JwtBearer

我希望这有帮助。如果你需要进一步的帮助,你可以在你的问题中添加更多的细节,我会帮助你