从标题Asp.Net Core WebApi绑定自定义对象

fle*_*xit 5 c# attributes model-binding request-headers asp.net-core-webapi

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

Raj*_*mar 1

使用IModelBinder 和 IModelBinderProvider编写自定义绑定器应该可以解决您的问题。