Right way to read range header from IHeaderDictionary object

1.2k views Asked by At

I have an ActionContext object.

I want to read the Range header from the Request. What I know is that I can read it like this

var rangeHeader = context.HttpContext.Request.Headers["Range"]

but then I have to split the string to get range from and to values because range header comes like this byte=100-512

So is this the right way to read this header from IHeaderDictonary or is there a better way to do this?

1

There are 1 answers

0
Kino101 On

I just found out what might be the "official" way to do it:

Add the following nuget to your project «Microsoft.AspNetCore.Http.Extensions».

And then do this:

var range = context.Request.GetTypedHeaders().Range;

And you're done :)