Add CORS Header to an ASP.NET MVC project
February 17, 2020
Web.config (IIS)
code
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="https://other.mydomain.net" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Authorization" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Hinweis: Wenn <configuration> oder <system.webServer> schon existiert, nur den fehlenden Teil einfuegen.
Test (Browser)
code
fetch("https://main.mydomain.net/Snapshot/landing-grid-mobile?count=12")
.then((r) => r.json())
.then(console.log);