Ich habe Rest-Anwendung mit Angular2 und ASP MVC Rest Server und ich habe ein Problem mit der Kommunikation. Wenn ich sende, bekomme ich diesen Fehler:ASP MVC Web API mit Angular2 - Http Header Access-Control
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:4200 ' is therefore not allowed access.
Wenn ich Access-Control-Allow-Origin hinzugefügt zu verlangen, ich diesen Fehler:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:4200 ' is therefore not allowed access. The response had HTTP status code 404.
Hier ist mein Code:
let headers = new Headers({ 'Access-Control-Allow-Origin': '*' })
this.http.get("http://localhost/App/Users", { withCredentials: true, headers: headers })
.subscribe(response => {
console.log("A");
}, error => {
console.log(error);
});
In web.config ist die Windows-Authentifizierung aktiviert. Wo ist das Problem?
Wie können Sie in web api cors aktivieren? – hasan