我有一个基本的股票标准ASP.Net 5 (ASP NET Core 1) MVC 6 (MVC Core 1)
控制器,只有一种让我感到悲伤的方法。
以下是有问题的方法:
// Get the table data
[HttpPost("data/{requestedTable}")]
public IActionResult GetTableData(string requestedTable, [FromForm] DataTableData post)
{
_logger.LogInformation($"About to process {requestedTable}");
_logger.LogInformation($"Draw {post.Draw}, Start {post.Start}");
if (!SQL.ValidTable(requestedTable))
{
return new ErrorObjectResult("Invalid table name specified");
}
var count = post.Length;
var start = post.Start;
var search = post.Search.Value;
var draw = post.Draw + 1;
var recordsTotal = new SQL()
.WithCount()
.AllData(requestedTable)
.FirstOrDefault()["COUNT"];
var recordsFiltered = new SQL()
.WithCount()
.WithSearch(search)
.WithNavigation()
.AllData(requestedTable)
.FirstOrDefault()["COUNT"];
var data = new SQL()
.WithLimit(count, start)
.WithSearch(search)
.WithNavigation()
.OrderBy(OrderHelper.Convert(post))
.EnableDataTable()
.AllData(requestedTable);
_logger.LogInformation($"Got: {recordsTotal}, {recordsFiltered}, {data.Count()}");
return new CustomObjectResult(new {
draw = draw,
recordsTotal = recordsTotal,
recordsFiltered = recordsFiltered,
data = data
});
}
它在我的开发系统上运行100%(Windows 10 Pro,VS 2015 w / IIS Express,DNVM 1.0.0-rc1-update1)。
但是,当我通过VM在Windows Server 2012 R2上运行它时,我将获得大约10-20个失败请求的成功请求。
以下是我将收到的示例日志:
<!-- GOOD REQUEST -->
info: Microsoft.AspNet.Hosting.Internal.HostingEngine[1]
Request starting HTTP/1.1 POST http://<removed>/api/backend/datatable/data/AncillaryShiftReport application/x-www-form-urlencoded; charset=UTF-8 2266
info: ProdManSys.Middleware.AuthRemapping[0]
Auth remap starting
info: ProdManSys.Middleware.AuthRemapping[0]
SID is currently S-1-5-21-xxxxx....
info: Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker[1]
Executing action method ProdManSys.Controllers.Api.Backend.DataTableController.GetTableData with arguments (AncillaryShiftReport, ProdManSys.Controllers.Api.Backend.Helpers.DataTableData) - ModelState is Valid'
info: ProdManSys.Controllers.Api.Backend.DataTableController[0]
About to process AncillaryShiftReport
info: ProdManSys.Controllers.Api.Backend.DataTableController[0]
Draw 1, Start 0
info: Microsoft.AspNet.Hosting.Internal.HostingEngine[2]
Request finished in 0.0016ms 200
info: ProdManSys.Controllers.Api.Backend.DataTableController[0]
Got: 18, 18, 10
<!-- BAD REQUEST -->
info: Microsoft.AspNet.Hosting.Internal.HostingEngine[1]
Request starting HTTP/1.1 POST http://<removed>/api/backend/datatable/data/AncillaryShiftReport application/x-www-form-urlencoded; charset=UTF-8 2266
info: ProdManSys.Middleware.AuthRemapping[0]
Auth remap starting
info: ProdManSys.Middleware.AuthRemapping[0]
SID is currently S-1-5-21-xxxxx....
info: Microsoft.AspNet.Hosting.Internal.HostingEngine[2]
Request finished in 0ms 200
是否有人遇到类似/有任何可能解决此问题的建议修补程序/有任何与此相关的调试提示吗?
答案 0 :(得分:0)
对于遇到此问题的人,[FromForm]
似乎有问题,将其更改为[FromBody]
并将其转换为具有相应类型的JSON已成功解决了此问题。
根据@BalaSakthis,以下问题在某种程度上解决了我的问题:ASP.NET 5 Controller method can't receive JSON POST, ASP.NET 4 controller method does