Last-Modified Header in Asp.net Core MVC

public class YourController : Controller
{
public ActionResult MyPage(string id)
{
var entity = _db.Get(id);
var headerValue = context.HttpContext.Request.Headers['If-Modified-Since'];
if (headerValue != null)
{
var modifiedSince = DateTime.Parse(headerValue).ToLocalTime();
if (modifiedSince >= entity.UpdatedAt)
{
 context.HttpContext.Response.StatusCode = 304;
return new EmptyResult();
}
} // page has been changed.
// generate a view ... // .. and set last modified in the date format specified in the HTTP rfc.
context.HttpContext.Response.AddHeader('Last-Modified', entity.UpdatedAt.ToUniversalTime().ToString("R"));
}
}
上一篇:JS,JQ及时监听input值的变化,MUI的input搜索框里的清除按钮的点击监听事件


下一篇:Android API Guides---Searchable Configuration