2017-05-09 4 views
0

私はPrimeNgのファイルアップロードを使用しています。私のAPIはWindows認証を有効にしています。今URLがmodel.idを使用して、コンストラクタを介して生成し、urlは私もauthGuardがクッキーを追加するための私のコンポーネントに適用されているangel 4 primeng upload url windows認証クッキー

http://localhost:5200/api/v1/document/:id/Upload

となっています。

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コード

<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" 

アップロードしようとすると、401-unauthorizedエラーが発生します。いかなる提案も大歓迎です。

編集:私は、私は「ASP.NET_SessionId」という名前のクッキーを参照することができ、アップロードコントローラのが、他のURLの要求を送信する際にクッキーが設定されていない見ることができます。私はfileupload doesntがWindowsauthのた​​めのクッキーを追加するメカニズムを持っていると思う。

編集2:私はクッキーを追加するために私自身のhttpclientを書いています、それを介してそれを呼び出すことは可能ですか?

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; 
    } 
} 

答えて

関連する問題