Ich benutze Angular und asp.net API. Das Problem, mit dem ich konfrontiert bin: Wenn ich CORS in den API-Code einfüge, funktioniert es in Internet Explorer, funktioniert aber nicht in Chrome und Firefox. HierDer 'Access-Control-Allow-Origin'-Header enthält mehrere Werte' *, * ', aber nur einer ist erlaubt
ist der Fehler:
XMLHttpRequest cannot load http://localhost:41028/api/values/abc . The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Origin ' http://localhost:44796 ' is therefore not allowed access.
Dies ist der Code, den ich in der web.config
Datei hinzugefügt:
<system.webServer>
...
<httpProtocol>
<customHeaders>
<!-- Adding the following custom HttpHeader will help prevent CORS errors -->
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
...
</system.webServer>
In der WebApiConfigFile.cs
Datei, die ich hinzugefügt:
var CorsAttribute = new EnableCorsAttribute("* ","* ", "* ");
config.EnableCors(CorsAttribute);
Ich bin mit CORS zum ersten Mal. Jede Hilfe wird geschätzt.
Fügen Sie Header entweder statisch in der Datei web.config oder dynamisch mit dem Attribut cors hinzu. Nicht beide. –
Entschuldigung, können Sie erklären, wie ich sagte, ich bin neu .... mit Beispiel? Ich bin sogar neu fragen Fragen über Stapelüberlauf – trigri
habe es danke für die Hilfe ... :) – trigri