0

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

Community
  • 1
  • 1
Tim
  • 531
  • 2
  • 7
  • 25

1 Answers1

0

There are a couple of similar questions to this if you are looking to do a long poll solution.

Comet implementation for ASP.NET?

The general consenus is that it can be tricky to scale.

There is also this implementation example

https://bitbucket.org/jacob4u2/mvcchatsite/src

Community
  • 1
  • 1
David
  • 8,340
  • 7
  • 49
  • 71
  • yes I have read that thread an it all seemed as good examples. I guess as I'm not that familiar with MVC2 and doing long polling solutions many of the examples seemed as overkill. As I read about the thread ploblems with IIS we had to do a work around. Right now we are getting the data pushed to us. Because of that I made the ajax long polling solution that uses setTimeOut. So you think that checking the request headers will not do the trick?? – Tim May 12 '11 at 08:51