Hi,
CORs keeps blocking my web api calls. I have a dotnet core 3.1 web api project which I cant access at all when debugging.
My startup file looks like this
public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); #region AUTHENTICATION services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Issuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"])) }; }); #endregion services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => { options.AddPolicy("AllowOrigin", builder => builder.WithOrigins("https://localhost:44383", "http://localhost:53711") .WithMethods("GET", "POST").AllowAnyHeader()); }); }); services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseCors("AllowOrigin"); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } }
What else do I need to do to get this to work ? Any help will be much appreciated