繁体   English   中英

how do i pass a datatable from a .net core 5.0 web api to an angular front end as json?

[英]how do i pass a datatable from a .net core 5.0 web api to an angular front end as json?

My old .net core 2 web api project used newtonsoft to serialise a datatable to json which I then passed back to a front end (angular) site as json ie using something along the lines of:

  1. Create a function ie public IActionResult Countries_Get() , query a sql server database and populate a new sql datatable ie DataTable dtCountries = clsDB.Execute_To_DataTable("selCountries", lstDBParams, Request); .
  2. 从 function 返回带有 HTTPStatusCode 的数据表,例如 Ok ie return Ok(dtCountries);

上面的代码在 .net 5.0 项目(重新开始)中不再工作,并出现System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues. Path: $.Columns.DataType. System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues. Path: $.Columns.DataType.

我已经读到这是 Microsoft 的设计,因为它使用新的 System.Text.Json 命名空间是不安全的,我真的想以正确的方式前进,但经过数小时的搜索后,我离答案更近了。

有人可以建议如何做上述与原始应用程序相同的事情。

干杯

您似乎想直接返回一个 DataTable 作为结果。 事实上,这会导致安全问题。

您是否尝试过进行中间映射?

将您的 DataTable 属性放入一个新的 class 然后返回这个新的 class 作为结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM