Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
im setting up jwt( core web api) in my program.cs and when im trying to configure it gives me redunderline error "Configuration is a type,which is not valid to give context"
can you please help me?

What I have tried:

    .AddJwtBearer(options =>
        options.TokenValidationParameters = new TokenValidationParameters
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = true,
            ValidateIssuerSigningKey = true,
            ValidIssuer = Configuration["JWT:Issuer"],
            ValidAudience = Configuration["JWT:Audience"],
            IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWT:Key"]))


Updated 17-Nov-22 3:02am

At a guess, you're missing the Configuration property from your Startup class:
public class Startup
    public Startup(IConfiguration configuration)
        Configuration = configuration;

    public IConfiguration Configuration { get; }

Share this answer
use builder.Configuration["Jwt:xxxxxx"] instead of Configuration["Jwt:xxxxxx"] if you're using program.cs file.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900