-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Consider allowing binding header values to types other than string and string collections #5859
Comments
@DaniJG Which specific headers would you want to use this for? |
I'm sending an authentication token (Guid) in the header |
I found this issue while looking at a question on stackoverflow so it wasn't a specific scenario that I had in mind. However, I could see the need for Guids as in the sessionId header or a deviceId header. Dates could also be needed, for example with the Date header, any other standard header of type http-date or any custom headers used by your app. |
@rynowak do you recall if there was some reason we supported only strings? Was it to avoid having errors during binding? (Because we can pretty much always bind to strings.) Or we just didn't think to do it? |
It was just for YAGNI reasons. We wanted to wait for feedback. |
Hi guys, we really appreciate your work, perhaps I think this functionality should be implemeted. What kind of feedback you need? I'm trying a similar scenario like @DaniJG and I'm experiencing the same issue. Seems to redudant to always parse the string to a Guid struct. |
@kellermanrivero - this is exactly the kind of feedback we were waiting for. "Yes I need this, and I want to be able to convert to a guid". This is planned for 2.1 |
I must say, I really enjoy and appreciate the effort to engage with the community. Cheers! |
Not sure if you are just implementing to support guid. But would like implementation to mimic FromQuery behavior. In my scenario I was trying to use SomeAction([FromHeader(Name = "x-page-number")] pageNumber) |
@elmar-de-groot FromHeader already has this support. |
Will it support collections of int? |
Was this feature added to ASP.NET Core 2.1? |
@Shamshiel Yes, I've already used it |
@Marusyk So this should work? https://localhost:44342/api/values/1?guid=1d434c71-48ab-457b-a7e2-4e76a1f6bfdb Because it doesn't seem to work for me. |
Here you are passing guid as a query parameter but not as a header. So use
|
@Marusyk Yeah you are right. It was a stupid mistake on my side. I just created a quick example and stopped thinking on what I'm actually doing. Sorry -.-" |
Right now when attempting to bind a model/property from a header, any type that isn't a string or a string collection is ignored as per the
HeaderModelBinderProvider
implementation.There will be common cases where at least you might need to bind other value types like
int
,DateTime
orGuid
which will get silently ignored.I understand binding to complex objects, collections and dictionaries might pose a challenge but at least simple value types should be supported.
The text was updated successfully, but these errors were encountered: