c# - 从 header Asp.Net Core WebApi 绑定(bind)自定义对象

标签 c# attributes model-binding asp.net-core-webapi request-headers

如何从 header 绑定(bind)对象。我正在使用 [FromHeader(Name = "Custom-Object")] 但它似乎只能绑定(bind)字符串和字符串数组。我需要编写自定义绑定(bind)还是我在这里遗漏了什么?我想知道为什么 fromheader 不能像 frombody 那样绑定(bind)复杂的对象?

最佳答案

使用 IModelBinder and IModelBinderProvider 编写自定义 Binder 那应该可以解决您的问题。

关于c# - 从 header Asp.Net Core WebApi 绑定(bind)自定义对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43136386/

相关文章:

c# - 在 FormClosing 方法中处理是/否/取消消息框中的取消按钮

c# - 在枚举中使用特殊字符,例如% (C#3.0)

c# - 对于 MVC Model Binder,表单 POST 是否太大

c# - 2 部分 Windows 应用程序 : "windows service" + GUI to configure it

c# - 在 WebApi 和 MVC Controller 之间共享逻辑?

python - 如何覆盖 python 中的类属性访问?

c# - 将参数传递给提供给属性的类型

asp.net-mvc - 在不使用 Html.CheckboxList 等 HTML 帮助器的情况下将选中的复选框发布到 Controller 操作

asp.net-mvc - 模型绑定(bind)时查找 View 模型属性上的自定义属性

c# - IDisposable、ObjectDisposedException 和线程安全类型