c# - ASP.NET MVC API 操作返回 404,所有其他操作都有效
问题描述
我有一个调用 ASP.NET WEB API 的 Angular 应用程序。我在其中一个 api 控制器上添加了一个方法,它返回 404。可以毫无问题地调用同一控制器上的所有其他方法。该应用程序在 IIS 上本地托管。
API 动作:
[ActionName("GetOrgChart")]
[ResponseType(typeof(List<Object>))]
[HttpPost]
public IHttpActionResult GetOrgChart(string id)
{
EmployeeMasterPTOCoordinator emPTOCnator = new EmployeeMasterPTOCoordinator();
List<Object> orgChartData = emPTOCnator.GetOrgChart()
return Ok<List<Object>>(orgChartData);
}
来自 Angular 应用程序的 HTTP 发布调用:
function GetOrgChart(id) {
var deferred = $q.defer();
$http({
method: 'POST', cache: false,
url: 'localhost:81/api/Employee/EmployeeMaterPTO/GetOrgChart',
data: id
}).success(function(data){
deffered.resolve(data);
}).error(function(data){
deffered.resolve(data);
})
return deffered.promise;
}
关于可能导致这种情况的任何想法?我尝试从 IIS 的应用程序池中删除 api 并重新添加它。我已经查看了所有堆栈溢出并且无法找到解决方案
解决方案
删除 [HttpPost] 并将 [ActionName] 替换为
[Route("~/api/Employee/EmployeeMaterPTO/GetOrgChart/{id?}")]
public IHttpActionResult GetOrgChart(string id)
添加到您的 route.config 的顶部
routes.MapMvcAttributeRoutes();
并从请求中删除“ data: id ”
method: 'GET',
url: 'http://localhost:81/api/Employee/EmployeeMaterPTO/GetOrgChart/'+id
推荐阅读
- mysql - 在 go 中将“SELECT *”列(多个)读入 [][]string
- linux - recv 是否总是返回相同数量的传递给发送的数据?
- objective-c - 内部错误 FIRAuthErrorCodeInternalError 17999
- java - 如果所有元素都以相同的顺序结束,为什么要调整大小?
- xamarin.forms - Xamarin.Forms AppCenter 当应用程序在后台或终止时推送
- django - Django迁移错误表已经存在
- sql-server - 另一个 AWS 账户使用节点 Js 或 Python 中的 Lambda 调用在第一个 AWS 账户中运行的 RDS(SQL Server)资源
- angular - 如何从 txt URL 获取文本?如何使用 Angular 7 中的 Filereader?
- ruby - 将 Hyperstack 组件/模型限制为仅某些特定页面工作所需的组件/模型?
- android - 使用多界面访问 android room DB 的最佳解决方案是什么?