如何实现条件get?

发布于 11-06 11:35 字数 954 浏览 7 评论 0原文

我正在尝试在我的控制器中实现条件获取。几天前我问了一个类似的问题,但几乎没有得到任何答案:在控制器中处理 HTTP 标头和状态代码 我想也许我没有正确解释自己,所以我正在尝试新的尝试。所以就是这样。从前端我正在做一个长轮询解决方案,我定期获取数据。数据以 json 格式出现。在我的控制器中,我返回结果集。我想做的是检查请求标头,这样如果自上次获取后没有修改,我将不会再次获取数据。这是我到目前为止所得到的:

 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");

            }

    }

请记住,我已经改变了几次,而且我很累,所以这里可能有一些明显的错误。我正在从数据库中获取数据。我可能会说数据显示在谷歌地图解决方案上。那么有人有什么建议吗?感谢您的指点。

问候

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末2024-11-13 11:35:08

如果您正在寻求进行长轮询解决方案,则有几个类似的问题。

ASP.NET 的 Comet 实现?

普遍的共识是扩展可能很棘手。

还有这个实现示例

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文