【发布时间】:2019-07-08 13:21:11
【问题描述】:
我试图通过传递一个字符串值并得到 404 not found 错误从我的 angular 7 应用程序调用我的 asp.net web api 端点。如果您在下面看到我正在调用 getDocumentUploadDetailsByIds 并将字符串传递给它。我正在将整数数组转换为字符串并发送它
网址如下所示:http://localhost:56888/api/documentupload/detailsByIds/591006,591007
组件
public createDocument() {
const documents: IDocumentDetails[] = this.files.map(doc => {
return { // notice just a curly bracket, and in the same line with 'return'
file: doc.fileDropEntry.fileEntry,
documentTypeId: doc.selectedDocumentItem.Id,
name: doc.name,
documentDate: doc.selectedDate
};
});
this.documents = { managerStrategyId: 0, documentDetails: null };
this.documents.managerStrategyId = this.ManagerStrategyId;
this.documents.documentDetails = documents;
this.documentUploadService.createDocumentUpload(this.documents)
.then((result) => {
if (result) {
this.documentIds.ids = Object.keys(result).map(k => result[k]);
this.getDocumentUploadDetailsByIds(this.documentIds.ids.toString());
this.setGridOptions();
this.setColumns();
this.notify.success('Documents uploaded Successfully');
}
}).catch(err => {
this.notify.error('An Error Has Occured While uploading the documents');
});
}
public getDocumentUploadDetailsByIds(documentIds) {
if (this.ManagerStrategyId != null) {
this.Loading = true;
this.initGrid();
this.documentUploadService.getDocumentUploadDetailsByIds(documentIds)
.subscribe(data => {
this.DocumentUploadDetails = data;
this.Loading = false;
},
err => {
this.Error = 'An error has occurred. Please contact BSG';
},
() => {
});
}
}
服务组件
getDocumentUploadDetailsByIds(documentIds: string) {
return this.mgr360CommonService.httpGet('/api/documentupload/detailsByIds/' + documentIds );
}
httpGet(url: string): Observable<any> {
return this.httpClient.get( this.webApiLocation + url, httpPostOptions)
.pipe(map((response: Response) => {
return response;
}), catchError(error => {
this.onError(error);
return Promise.reject(error);
}));
}
服务器端
[HttpGet]
[SkipTokenAuthorization]
public IHttpActionResult DetailsByIds(string documentIds)
{
var viewModel = GetDocumentUploadDetailsByIds(documentIds);
return Ok(viewModel);
}
【问题讨论】:
-
您是如何在 ASP.NET 项目中配置路由表的? (在你的项目中搜索
.MapHttpRoute)