Я использую Microsoft.ApsNetCore.Cors 2.2
"Доступ к XMLHttpRequest по адресу" exampleapi.local "
из источника 'example.local' был заблокирован политикой CORS:
Заголовок «Access-Control-Allow-Origin» отсутствует в запрошенном
ресурс ".
Я установил настройки с помощью этого
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin",
builder =>
{
builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
services.Configure<TokenSettings>(this.Configuration.GetSection("Tokens"));
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(opt =>
{
opt.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Tokens:Issuer"],
ValidAudience = Configuration["Tokens:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Tokens:SecurityKey"]))
};
});
services.AddMvc();
services.Configure<LdapConfig>(Configuration.GetSection("ldap"));
services.AddScoped<ILdapAuthenticationService, LdapAuthenticationService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IProjectService, ProjectService>();
services.AddScoped<IProjectMembersService, ProjectMembersService>();
services.AddScoped<IJourneyUsersService, JourneyUsersService>();
services.AddScoped<IProjectRolesService, ProjectRolesService>();
services.AddScoped<IPmoGuardianService, PmoGuardianService>();
services.AddScoped<IHolidaysService, HolidaysService>();
services.AddScoped<IMailService, MailService>();
services.AddScoped<INotificationsService, NotificationsService>();
services.AddScoped<INotificationUsersService, NotificationUsersService>();
services.Configure<AWSConfigSes>(Configuration.GetSection("AWSSmtp"));
services.AddDbContext<JourneyContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("JourneyConnection")));
services.AddDbContext<TSMContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("TSMConnection")));
services.AddDbContext<PmoGuardianContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("PmoGuardianConnection")));
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMailService mail, INotificationsService not)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
Recurrence recurrency = Recurrence.GetInstance(not);
//new TSMClockService(mail);
app.UseCors("AllowSpecificOrigin");
app.UseAuthentication();
app.UseMvc();
}
[Produces("application/json")]
[Route("api/Mail")]
[EnableCors("AllowSpecificOrigin")]
Но это не работает, всегда я получаю одну и ту же ошибку