Проблема с CORS на ASP.NET Web API
Есть приложение - класический Web APi на .NET без авторизации и всяких наворотов - просто методы WEB API.
Не получается заставить работать через CORS. Не работают методы DELETE и PUT
вставка заголовков в web.config и прочие стандартные методы не срабатывают.
Нужно понять проблема в приложении или в настройке IIS.
Если окажется что в IIS зайти удаленно настроить.
Описать решение чтобы можно было повторить на продакшене.
-
124 Добрый день! Готов настроить CORS в вашем проекте за кратчайшие сроки.
-
можно
https://drive.google.com/open?id=1Qm0yzqRebb4DSVP-OVNrk2WhdGRFzYHA
интересно что корс вываливается когда добавляешь в запрос contentType: "application/json"
-

И самое важное
CORS - для безопастности, мы регулируем какие домены(origins) могут обращаться к вашим WebAPI с какими заголовками(application/json) и какие запросы(PUT, DELETE,...) им разрешены
Т/е мы его используем для ограничения - для безопасности
Например, у меня есть Web API .Net он запущен на моем сервере и внутренний адрес: localhost:3000, а внешний https://examle.com
Внутри программы .net я пишу
services.AddCors();
AllowAnyHeader() - разрешаю любые заголовки в том числе application/json;
AllowAnyMethod(); - разрешаю любые методы PUT, POST, …
У меня указано WithOrigins(“http://localhost:3000”)!! т/е к моему api могут обращаться только сервисы запущенные с текущего локального сервера и порта (with origin: localhost:3000/* or example.com/*(nginx настройки)) иначе будет ошибка
Попробуйте добавить адреса с которых обращается фронтендер, например в WebAPI .net перед контроллерами
[EnableCors(origins: "http://www.адрес-фронтендера.com", headers: "*", methods: "*")]
public class ItemsController : ApiController {}
Или глобально
-
Current freelance projects in the category C#
S1GG1LA person is needed who can take the initial code of the Minecraft launcher for the project, change the design at their discretion, but there are small style requirements for it to be in purple tones. Regarding payment, please suggest a price for the work. However, the budget is… C#, Gaming Apps ∙ 1 day 2 hours back ∙ 5 proposals |
Improvement in the existing version of 1C retail block for the distribution center (DC)In general, I will explain what kind of database we have - There is a main server where there is a retail database (where all receipts are recorded) - a UTP database - where all sales are transferred - it calculates the markup and stock balances - small databases of retail… C & C++, C# ∙ 6 days 2 hours back ∙ 6 proposals |
It is necessary to migrate the current working program from FoxPro to C#.Hello everyone! We have a program in FoxPro (it has several modules, it's an accounting program), we have the source code of the program, and if necessary, we can consult with people who support the current program. What needs to be done: 1. Analyze how everything works,… C#, Desktop Apps ∙ 8 days 17 hours back ∙ 18 proposals |
Junior C#We are looking for a talented and ambitious Junior C# developer who is eager for professional growth and new challenges. Your future tasks: - Development and support of backend solutions with frontend (Telegram bot); - Automation of routine processes in Android development,… C# ∙ 9 days 7 hours back ∙ 9 proposals |