ASP.NET MVC : how do I return 304 “Not Modified” status?

后端 未结 3 1477
無奈伤痛
無奈伤痛 2020-12-16 12:09

ASP.NET MVC 3.0, IIS 7, .NET 4

I have an action that returns data that seldom changes (almost static).

Is there an easy way to:

  1. return 304 \"
3条回答
  •  清歌不尽
    2020-12-16 13:08

    Whats wrong with this for 304?

            Response.StatusCode = 304;
            Response.StatusDescription = "Not Modified";
            return Content(String.Empty);
    

    and this for LastModified:

            Response.Cache.SetLastModified(DateTime.Now);
    

    Or maybe just create a 'Not Modified' Filter.

提交回复
热议问题