Ich benutze File-Upload von PrimeNg und ich habe Windows-Authentifizierung für meine API aktiviert. jetzt URL generiert durch Konstruktor model.id und URL wirdeckig 4 primeng upload url windows authentifizierung cookie
Ich habe auch authGuard für das Hinzufügen von Cookie auf meine Komponenten angewendet.
Routes.ts
const routes: Routes = [
{
path: '', component: HomeComponent, pathMatch: 'full', canActivate: [AuthGuard]
},
{ path: 'factory', component: FactoryFormComponent, canActivate: [AuthGuard]},
{ path: 'factory/:id', component: FactoryFormComponent, canActivate: [AuthGuard] },
{ path: 'supplier', component: SupplierFormComponent, canActivate: [AuthGuard] },
{ path: 'supplier/:id', component: SupplierFormComponent, canActivate: [AuthGuard] },
{ path: 'businessarea', component: BusinessAreaFormComponent, canActivate: [AuthGuard] },
{ path: 'businessarea/:id', component: BusinessAreaFormComponent, canActivate: [AuthGuard] },
{ path: 'document/:id/Upload', component: EventFormComponent, canActivate: [AuthGuard] }
];
HTML-Code
<div *ngIf="model.id">
<p-fileUpload name={{model.id}} url={{documentUploadUrl}} (onUpload)="onUpload($event)" (onError)="onError($event)"
multiple="multiple" accept=".txt" maxFileSize="10000000">
<template pTemplate type="content">
<ul *ngIf="uploadedFiles.length">
<li *ngFor="let file of uploadedFiles">{{file.name}} - {{file.size}} bytes</li>
</ul>
</template>
</p-fileUpload>
</div>
packages.json
"@angular/animations": "^4.1.1",
"@angular/common": "^4.1.1",
"@angular/compiler": "^4.1.1",
"@angular/core": "^4.1.1",
"@angular/forms": "^4.1.1",
"@angular/http": "^4.1.1",
"@angular/platform-browser": "^4.1.1",
"@angular/platform-browser-dynamic": "^4.1.1",
"@angular/router": "^4.0.0",
"bootstrap": "3.3.7",
"core-js": "^2.4.1",
"font-awesome": "^4.6.3",
"ng2-completer": "^0.2.2",
"primeng": "^4.0.0",
"rxjs": "^5.3.0",
"zone.js": "0.8.5"
wenn ich versuche, es hochladen gibt 401-unberechtigten Fehler. Jeder Vorschlag ist willkommen.
bearbeiten: Ich kann es sehen kein Cookie gesetzt wird, wenn Anforderung für den Upload-Controller sendet, aber für andere URLs kann ich Cookie mit dem Namen „ASP.NET_SessionId“ sehen. Ich vermute, dass Fileupload keinen Mechanismus zum Hinzufügen von Cookies für Windowsauth hat.
Edit 2: Ich habe meinen eigenen httpclient geschrieben, den ich verwende, um Cookies hinzuzufügen, ist es möglich, es durch das zu nennen?
httpclient.ts
@Injectable()
export class HttpClient extends Http {
constructor(backend: ConnectionBackend,
defaultOptions: RequestOptions) {
super(backend, defaultOptions);
}
get(url: string, options?: RequestOptionsArgs): Observable<any> {
return super.get(url, this.AddCustomOptions(options));
}
post(url: string, body: any, options?: RequestOptionsArgs): Observable<any> {
return super.post(url, body, this.AddCustomOptions(options));
}
put(url: string, body: any, options?: RequestOptionsArgs): Observable<any> {
return super.put(url, body, this.AddCustomOptions(options));
}
private AddCustomOptions(options: RequestOptionsArgs): RequestOptionsArgs {
if (options)
options.withCredentials = true;
else
options = new RequestOptions({
withCredentials: true
});
return options;
}
}