I'm trying to implement an conditional get in my controller. I asked a similar question a few days ago but did hardly get any answers on that one: Handle HTTP-Headers and status codes in controller I thought that maybe I did not explain myself correctly so I'm giving at an new try. So here it is. From the front end I'm doing a long poll solution where I fetch data with an regular interval. The data comes in the format of json. In my controller I'm returning the resultset. What I would like to do is to check the request headers so that if not modified since last fetch I wont get the data again. This is what I got so far:
public ActionResult Index()
{
var ifModifiedSince = Request.Headers["If-Modified-Since"];
if( !String.IsNullOrEmpty( ifModifiedSince ) )
{
Response.StatusCode = 304;
Response.StatusDescription = "304 Not Modified";
Response.End();
return new EmptyResult(); <--- not sure what I should return here.
}
else
{
return View("Index");
}
}
Bare in mind that this I have changed several times and I'm quite tired so there migth be some obvious errors here. I am fetching the data from a database. I might ad that the data is displayed on a google map solution. So does anyone have any suggestions?? Thankful for any pointers.
Regards