Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3237044
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:41:31+00:00 2026-05-17T17:41:31+00:00

I have a database that stores images which can be access via a primary

  • 0

I have a database that stores images which can be access via a primary key ID (vomit, I know, but it’s out of my control).

I have a pretty standard Asp .net Mvc Controller that reads the database and if a row is found in the database it returns the image bytes as a FileResult. If a row is not found, I have a custom action result that sets the response status to 404. I do not throw an exception, but instead let IIS handle the 404 status and return a static file.

public class ContentMediaNotFoundResult : ActionResult
{
    public ContentMediaNotFoundResult() { }

    public override void ExecuteResult(ControllerContext context)
    {
        //-- Here the only thing we are doing is setting the Response code to 404 and then we are   going to let IIS service the request
        //-- based on the settings in system.webServer/httpErrors (which may come from the root .config, so be careful)
        context.HttpContext.Response.StatusCode = 404;
    }
}

Recently, we were testing on Firefox v3.6.1 and were noticing the browser was making multiple requests (3 to be precise) for each image, hence our controller factory was being hit 3 times and going to the database 3 times from our action method. This behavior was only happneing from Firefox (IE, chrome were normal).

My question is, does it make sense to add Http Cache Headers to 404 responses in my ContentMediaNotFoundResult so that my action method doesn’t hit the database continually.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:41:32+00:00Added an answer on May 17, 2026 at 5:41 pm

    Sure, you can set Cache headers for 404s. As @Darin mentioned, your cache aging may affect any issues with replacing a 404’d image, but that’s the same problem with caching any object that may change.

    Seems like only 5xx errors should probably not be cached, but 4xx are fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql database that stores some documents. A user can sign into
I have a database that i'm dealing with which is updated every few hours
I have a database with DateTime fields that are currently stored in local time.
I have a c# application that interfaces with the database only through stored procedures.
I have a database that contains a date and we are using the MaskedEditExtender
I have a database that I would like class files generated from, and also
I have a database that many different client applications (a smattering of web services,
I have a database that contains a table that looks a bit like this:
I have a database that is stuck in single-user mode. I kill the process
We have a database that persist our metadata and data. Our metadata is produced

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.