.net core how to add Content-range to header
I'm having no luck find out how to add Content-Range to the header of my odata requests. My api requires a format as such for paging:
Content-Range: posts 0-24/319
The closest thing I can find is HTTP Byte Range Support. From here:
https://blogs.msdn.microsoft.com/webdev/2012/11/23/asp-net-web-api-and-http-byte-range-support/ . The OP says a post will be written about [Queryable] which is supposed to add support for paging, but I have yet to see any info on this.
[EnableQuery]
[ODataRoute]
public IActionResult Get(ODataQueryOptions<HC_PortalActivity>
options)
{
return Ok(Db.HC_PortalActivity_Collection);
}
.net-core odata
add a comment |
I'm having no luck find out how to add Content-Range to the header of my odata requests. My api requires a format as such for paging:
Content-Range: posts 0-24/319
The closest thing I can find is HTTP Byte Range Support. From here:
https://blogs.msdn.microsoft.com/webdev/2012/11/23/asp-net-web-api-and-http-byte-range-support/ . The OP says a post will be written about [Queryable] which is supposed to add support for paging, but I have yet to see any info on this.
[EnableQuery]
[ODataRoute]
public IActionResult Get(ODataQueryOptions<HC_PortalActivity>
options)
{
return Ok(Db.HC_PortalActivity_Collection);
}
.net-core odata
Please explain where you are trying to add the header? Before it gets to your controller method? What have you tried so far?
– Simply Ged
Nov 18 '18 at 23:03
add a comment |
I'm having no luck find out how to add Content-Range to the header of my odata requests. My api requires a format as such for paging:
Content-Range: posts 0-24/319
The closest thing I can find is HTTP Byte Range Support. From here:
https://blogs.msdn.microsoft.com/webdev/2012/11/23/asp-net-web-api-and-http-byte-range-support/ . The OP says a post will be written about [Queryable] which is supposed to add support for paging, but I have yet to see any info on this.
[EnableQuery]
[ODataRoute]
public IActionResult Get(ODataQueryOptions<HC_PortalActivity>
options)
{
return Ok(Db.HC_PortalActivity_Collection);
}
.net-core odata
I'm having no luck find out how to add Content-Range to the header of my odata requests. My api requires a format as such for paging:
Content-Range: posts 0-24/319
The closest thing I can find is HTTP Byte Range Support. From here:
https://blogs.msdn.microsoft.com/webdev/2012/11/23/asp-net-web-api-and-http-byte-range-support/ . The OP says a post will be written about [Queryable] which is supposed to add support for paging, but I have yet to see any info on this.
[EnableQuery]
[ODataRoute]
public IActionResult Get(ODataQueryOptions<HC_PortalActivity>
options)
{
return Ok(Db.HC_PortalActivity_Collection);
}
.net-core odata
.net-core odata
edited Nov 16 '18 at 15:21
Jesse
asked Nov 13 '18 at 21:20
JesseJesse
7351822
7351822
Please explain where you are trying to add the header? Before it gets to your controller method? What have you tried so far?
– Simply Ged
Nov 18 '18 at 23:03
add a comment |
Please explain where you are trying to add the header? Before it gets to your controller method? What have you tried so far?
– Simply Ged
Nov 18 '18 at 23:03
Please explain where you are trying to add the header? Before it gets to your controller method? What have you tried so far?
– Simply Ged
Nov 18 '18 at 23:03
Please explain where you are trying to add the header? Before it gets to your controller method? What have you tried so far?
– Simply Ged
Nov 18 '18 at 23:03
add a comment |
2 Answers
2
active
oldest
votes
You can add the Content-Range
header to your HttpRequest.Content
object:
request.Content.Headers.ContentRange = new System.Net.Http.Headers.ContentRangeHeaderValue(0, 24, 319);
request.Content.Headers.ContentRange.Unit = "posts";
Remember to set the Unit
otherwise it will default to `bytes'
EDIT
The Content
property is only available on the HttpRequestMessage
class, not the HttpRequest
class. So you will need to create one to be able to access the ContentRange
property.
var request = new HttpRequestMessage();
... // as above
Assuming you are using a HttpClient
to send your request you can pass the request in the SendAsync
method
var httpClient = new HttpClient();
... // other setup
httpClient.SendAsync(request);
Does this apply for .net core I'm having trouble accessing HttpRequest.Content
– Jesse
Nov 15 '18 at 19:20
Apologies. The property is on a HttpRequestMessage class (not the HttpRequest class) so you need to create one of them for your message. I've updated my answer to add this.
– Simply Ged
Nov 15 '18 at 20:43
I've updated my question to include what my Controller action looks like.
– Jesse
Nov 16 '18 at 15:21
This got me started thanks!
– Jesse
Nov 28 '18 at 21:14
add a comment |
Here is what I ended up doing:
public static void IncludeContentRange<T>(ODataQueryOptions<T> options, HttpRequest context)
{
var range = options.Request.Query["range"][0].Replace("[", "").Replace("]", "").Split(',');
var q = from x in Db.HC_PortalActivity_Collection
select x;
var headerValue = string.Format("{0} {1}-{2}/{3}", options.Context.NavigationSource.Name.ToLower(), range[0], range[1], q.Count());
context.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Range");
context.HttpContext.Response.Headers.Add("Content-Range", headerValue);
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289657%2fnet-core-how-to-add-content-range-to-header%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can add the Content-Range
header to your HttpRequest.Content
object:
request.Content.Headers.ContentRange = new System.Net.Http.Headers.ContentRangeHeaderValue(0, 24, 319);
request.Content.Headers.ContentRange.Unit = "posts";
Remember to set the Unit
otherwise it will default to `bytes'
EDIT
The Content
property is only available on the HttpRequestMessage
class, not the HttpRequest
class. So you will need to create one to be able to access the ContentRange
property.
var request = new HttpRequestMessage();
... // as above
Assuming you are using a HttpClient
to send your request you can pass the request in the SendAsync
method
var httpClient = new HttpClient();
... // other setup
httpClient.SendAsync(request);
Does this apply for .net core I'm having trouble accessing HttpRequest.Content
– Jesse
Nov 15 '18 at 19:20
Apologies. The property is on a HttpRequestMessage class (not the HttpRequest class) so you need to create one of them for your message. I've updated my answer to add this.
– Simply Ged
Nov 15 '18 at 20:43
I've updated my question to include what my Controller action looks like.
– Jesse
Nov 16 '18 at 15:21
This got me started thanks!
– Jesse
Nov 28 '18 at 21:14
add a comment |
You can add the Content-Range
header to your HttpRequest.Content
object:
request.Content.Headers.ContentRange = new System.Net.Http.Headers.ContentRangeHeaderValue(0, 24, 319);
request.Content.Headers.ContentRange.Unit = "posts";
Remember to set the Unit
otherwise it will default to `bytes'
EDIT
The Content
property is only available on the HttpRequestMessage
class, not the HttpRequest
class. So you will need to create one to be able to access the ContentRange
property.
var request = new HttpRequestMessage();
... // as above
Assuming you are using a HttpClient
to send your request you can pass the request in the SendAsync
method
var httpClient = new HttpClient();
... // other setup
httpClient.SendAsync(request);
Does this apply for .net core I'm having trouble accessing HttpRequest.Content
– Jesse
Nov 15 '18 at 19:20
Apologies. The property is on a HttpRequestMessage class (not the HttpRequest class) so you need to create one of them for your message. I've updated my answer to add this.
– Simply Ged
Nov 15 '18 at 20:43
I've updated my question to include what my Controller action looks like.
– Jesse
Nov 16 '18 at 15:21
This got me started thanks!
– Jesse
Nov 28 '18 at 21:14
add a comment |
You can add the Content-Range
header to your HttpRequest.Content
object:
request.Content.Headers.ContentRange = new System.Net.Http.Headers.ContentRangeHeaderValue(0, 24, 319);
request.Content.Headers.ContentRange.Unit = "posts";
Remember to set the Unit
otherwise it will default to `bytes'
EDIT
The Content
property is only available on the HttpRequestMessage
class, not the HttpRequest
class. So you will need to create one to be able to access the ContentRange
property.
var request = new HttpRequestMessage();
... // as above
Assuming you are using a HttpClient
to send your request you can pass the request in the SendAsync
method
var httpClient = new HttpClient();
... // other setup
httpClient.SendAsync(request);
You can add the Content-Range
header to your HttpRequest.Content
object:
request.Content.Headers.ContentRange = new System.Net.Http.Headers.ContentRangeHeaderValue(0, 24, 319);
request.Content.Headers.ContentRange.Unit = "posts";
Remember to set the Unit
otherwise it will default to `bytes'
EDIT
The Content
property is only available on the HttpRequestMessage
class, not the HttpRequest
class. So you will need to create one to be able to access the ContentRange
property.
var request = new HttpRequestMessage();
... // as above
Assuming you are using a HttpClient
to send your request you can pass the request in the SendAsync
method
var httpClient = new HttpClient();
... // other setup
httpClient.SendAsync(request);
edited Nov 15 '18 at 20:43
answered Nov 13 '18 at 23:53
Simply GedSimply Ged
2,37321321
2,37321321
Does this apply for .net core I'm having trouble accessing HttpRequest.Content
– Jesse
Nov 15 '18 at 19:20
Apologies. The property is on a HttpRequestMessage class (not the HttpRequest class) so you need to create one of them for your message. I've updated my answer to add this.
– Simply Ged
Nov 15 '18 at 20:43
I've updated my question to include what my Controller action looks like.
– Jesse
Nov 16 '18 at 15:21
This got me started thanks!
– Jesse
Nov 28 '18 at 21:14
add a comment |
Does this apply for .net core I'm having trouble accessing HttpRequest.Content
– Jesse
Nov 15 '18 at 19:20
Apologies. The property is on a HttpRequestMessage class (not the HttpRequest class) so you need to create one of them for your message. I've updated my answer to add this.
– Simply Ged
Nov 15 '18 at 20:43
I've updated my question to include what my Controller action looks like.
– Jesse
Nov 16 '18 at 15:21
This got me started thanks!
– Jesse
Nov 28 '18 at 21:14
Does this apply for .net core I'm having trouble accessing HttpRequest.Content
– Jesse
Nov 15 '18 at 19:20
Does this apply for .net core I'm having trouble accessing HttpRequest.Content
– Jesse
Nov 15 '18 at 19:20
Apologies. The property is on a HttpRequestMessage class (not the HttpRequest class) so you need to create one of them for your message. I've updated my answer to add this.
– Simply Ged
Nov 15 '18 at 20:43
Apologies. The property is on a HttpRequestMessage class (not the HttpRequest class) so you need to create one of them for your message. I've updated my answer to add this.
– Simply Ged
Nov 15 '18 at 20:43
I've updated my question to include what my Controller action looks like.
– Jesse
Nov 16 '18 at 15:21
I've updated my question to include what my Controller action looks like.
– Jesse
Nov 16 '18 at 15:21
This got me started thanks!
– Jesse
Nov 28 '18 at 21:14
This got me started thanks!
– Jesse
Nov 28 '18 at 21:14
add a comment |
Here is what I ended up doing:
public static void IncludeContentRange<T>(ODataQueryOptions<T> options, HttpRequest context)
{
var range = options.Request.Query["range"][0].Replace("[", "").Replace("]", "").Split(',');
var q = from x in Db.HC_PortalActivity_Collection
select x;
var headerValue = string.Format("{0} {1}-{2}/{3}", options.Context.NavigationSource.Name.ToLower(), range[0], range[1], q.Count());
context.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Range");
context.HttpContext.Response.Headers.Add("Content-Range", headerValue);
}
add a comment |
Here is what I ended up doing:
public static void IncludeContentRange<T>(ODataQueryOptions<T> options, HttpRequest context)
{
var range = options.Request.Query["range"][0].Replace("[", "").Replace("]", "").Split(',');
var q = from x in Db.HC_PortalActivity_Collection
select x;
var headerValue = string.Format("{0} {1}-{2}/{3}", options.Context.NavigationSource.Name.ToLower(), range[0], range[1], q.Count());
context.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Range");
context.HttpContext.Response.Headers.Add("Content-Range", headerValue);
}
add a comment |
Here is what I ended up doing:
public static void IncludeContentRange<T>(ODataQueryOptions<T> options, HttpRequest context)
{
var range = options.Request.Query["range"][0].Replace("[", "").Replace("]", "").Split(',');
var q = from x in Db.HC_PortalActivity_Collection
select x;
var headerValue = string.Format("{0} {1}-{2}/{3}", options.Context.NavigationSource.Name.ToLower(), range[0], range[1], q.Count());
context.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Range");
context.HttpContext.Response.Headers.Add("Content-Range", headerValue);
}
Here is what I ended up doing:
public static void IncludeContentRange<T>(ODataQueryOptions<T> options, HttpRequest context)
{
var range = options.Request.Query["range"][0].Replace("[", "").Replace("]", "").Split(',');
var q = from x in Db.HC_PortalActivity_Collection
select x;
var headerValue = string.Format("{0} {1}-{2}/{3}", options.Context.NavigationSource.Name.ToLower(), range[0], range[1], q.Count());
context.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Range");
context.HttpContext.Response.Headers.Add("Content-Range", headerValue);
}
answered Nov 28 '18 at 21:18
JesseJesse
7351822
7351822
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289657%2fnet-core-how-to-add-content-range-to-header%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please explain where you are trying to add the header? Before it gets to your controller method? What have you tried so far?
– Simply Ged
Nov 18 '18 at 23:03