How return 304 status with FileResult in ASP.NET MVC RC1

前端 未结 3 1266
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 16:03

As you may know we have got a new ActionResult called FileResult in RC1 version of ASP.NET MVC.

Using that, your action methods can ret

3条回答
  •  心在旅途
    2021-02-05 16:38

    In newer versions of MVC you'd be better off returning an HttpStatusCodeResult. That way you don't need to set the Response.StatusCode or mess with anything else.

    public ActionResult DisplayPhoto(int id)
    {
        //Your code to check your cache and get the image goes here 
        //...
        if (isChanged)
        {
             return File(photo.Content, photo.ContentType);
        }
        return new HttpStatusCodeResult(HttpStatusCode.NotModified);
    }
    

提交回复
热议问题