Search code examples
asp.nethttpwebformsresponsehttp-status-codes

Web forms: Return http status for no result found for paginated url?


We have a paginated URL like:

example.aspx/?pn=1
example.aspx/?pn=2
example.aspx/?pn=3
...

and so on.

This is web form URL that returns list of products. What should be returned back to the browser when we don't have any product for that request?

Should we return back like:

1. Response.StatusCode = 400; //Bad request
   Response.End();

 2. Response.StatusCode = 204; //No Content
    Response.End();

And should we use Respose.End() here? What is the correct way to inform client/crawlers that we don't have content on this page.


Solution

  • let us Assume the Products are returned as a JSON array, so obvious respnse to that one would be 200 with an Empty array .

    Returning 404 response that the resource doesn't exist, kind of saying that it isn't even possible to ask for the products for this particular user. But in reality , it's possible to successfully return the list of products , it's just that product list is empty . This is completely in contrast to retrieval of one specific Product using an ID that doesn't exist in such Situations a 404 is correct.

    While with 204 it at least tell your user that the request was successful and it had no content. In other terms The Resource DOES exist but for some reason but the server chosen not to include it in its body .

    A 204 can also be used as a response to a POST request where some action was carried out by the server without necessarily creating any new resource (which would have implied a 201 CREATED), or where it's for some other reason not relevant to return any resource.