Я получаю сообщение об ошибке при отправке почтового запроса из Angular в .net core
Сообщение об ошибке:
Доступ к XMLHttpRequest в «xxxx» из источника «yyyy» был заблокирован политикой CORS: в запрошенном ресурсе отсутствует заголовок «Access-Control-Allow-Origin».
Угловая сторона
add(item:AchievementsAddEdit){
let formData: FormData = new FormData();
for (const prop in item) {
if (!item.hasOwnProperty(prop)) { continue; }
formData.append(prop , item[prop]);
}
let headers = new HttpHeaders();
//headers.append("Authorization","Bearer"+this.authService.token);
this.httpClient.post(this.path + 'achievements/add',formData).subscribe(data=>{
//console.log(data);
},
error=>{
alert("Error Message: Fill in the required fields");
}
);
}
Серверный запуск startup.cs ConfigureServices
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
Обслуживать сторону Настроить
app.UseCors("CorsPolicy");
Web Config (опубликовать)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Unchained.API.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 14963db0-9f3a-4a6b-b384-b97dd96f61ad-->