CORS PREFLIGHT -Optionen Anfrage Rücksende 401 (nicht autorisiert) von Windows Authenticated Web APIC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 CORS PREFLIGHT -Optionen Anfrage Rücksende 401 (nicht autorisiert) von Windows Authenticated Web API

Post by Anonymous »

Ich habe ein .NET -Web -API -Projekt mit Windows Authentication . In meiner Entwicklungsumgebung kann ich keine erfolgreiche Post mit Daten aus meiner Angular -App durchführen. Es kehrt zurück: < /p>

Code: Select all

OPTIONS http://localhost:9090/api/values 401 (Unauthorized)
Failed to load http://localhost:9090/api/values: Response for preflight has invalid HTTP status code 401.
< /code>

Ich habe alle Mittel zur Implementierung von CORs mit microsoft.aspnet.webapi.cors < /code> ohne Erfolg ausprobiert. Derzeit habe ich das Paket von microsoft.aspnet.webapi.cors 
aus meinem Projekt zugunsten der web.config Methode entfernt (wenn ich tatsächlich noch microsoft.aspnet.webapi.cors benötige installiert, um Folgendes in web.config zu machen , plz lass es mich wissen) :

Web.config: < /strong> < /p>

Code: Select all








< /code>

.net Web API 'VALUTSCONTROLLER.CS': < /strong> < /p>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace api.Controllers
{
[Authorize]
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable Get()
{
return new string[] { "value1", "value2" };
}

// GET api/values/5
public string Get(int id)
{
return "value";
}

// POST api/values
public void Post([FromBody]string value)
{
}

// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}

// DELETE api/values/5
public void Delete(int id)
{
}
}
}
< /code>

 Winkelkomponente (sendet Daten an meinen Winkeldienst): < /strong> < /p>

  constructor(private myService: MyService) {
this.myService.myPost({ID: 1, FirstName: 'Bob'})
.subscribe(
data => console.warn(data),
err => console.error(err),
() => console.log("empty")
);
}
< /code>

 Winkeldienst (veröffentlicht die Daten der Komponente an meine Web -API < /code>): < /strong> < /p>

import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse, HttpRequest, HttpHeaders, HttpInterceptor, HttpHandler, HttpEvent, HttpParams} from '@angular/common/http';

import { Observable } from 'rxjs';
import { from } from 'rxjs';
import { map, filter, catchError, mergeMap } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
})
export class MyService {

constructor(private http: HttpClient) {

};

public myPost(body) {

const httpOptions = {
withCredentials: true
}

return this.http.post("http://localhost:9090/api/values", body, httpOptions);

}

}
Aus meiner Forschung scheint ich vielleicht eine Autorisierung in meiner Anfrage über meine HttpOPTIONS -Variable im Dienst übergeben muss. Aber ich weiß nicht, was ich als Wert für die Autorisierung Eigenschaft geben soll. Siehe die Fragezeichen unten:
MyService.ts[/b]

public myPost(body) {
const httpOptions = {
headers: new HttpHeaders({
'Authorization': '?????'
}),
withCredentials: true
}
return this.http.post("http://localhost:9090/api/values", body, httpOptions);
}
< /code>

Vielleicht ist dies jedoch nicht einmal mein Problem. CORS + Windows -Authentifizierung - irgendwelche Ideen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post