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 9173681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:37:36+00:00 2026-06-17T16:37:36+00:00

I do the following code to check if an image exists: public bool DoesImageExist(string

  • 0

I do the following code to check if an image exists:

 public bool DoesImageExist(string imageUrl)
{
    bool exists = false;
    try
    {
        HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(imageUrl);
        request.Timeout = 5000;
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            exists = (response.StatusCode == HttpStatusCode.OK);
        }
    }
    catch
    {
        exists = false;
    }

    return exists;
}

This works fine and returns a 404 for images that don’t exist, however since I switched on customErrors in the web.config, it started returning 200 status ok, because the image it requests returns a 404 and redirects to the error handler page which returns a 200 status ok. Is there a way around this to prevent the customErrors page from returning a 200 ok or working for images?

  • 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-06-17T16:37:36+00:00Added an answer on June 17, 2026 at 4:37 pm

    I found a quick way around this for anyone with the same problem by putting this code into my generic handler page (which I set in customErrors)

    if (Request.Params.ToString().Contains("jpg") || Request.Params.ToString().Contains("png"))
            Response.StatusCode = 404;
    

    This basically forces it to return a 404 for any jpeg/png images, however for all other errors it forces the generic page to be shown.

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

Sidebar

Related Questions

Please check out my following code... public enum LogType { Debug, Info, Warn, Error,
I have the following code: <div id=slideshow > <div class=check> <img src=images/slideshow/image01.jpg alt=Slideshow Image
I want to choose images from the Gallery. Please check the following code. public
I have the following PHP code // Check if the upload is setted if
I am using following code to check whether a check box on my website
Please check following code tell me what the difference between Convert.ToInt32() and int() ,
Check the following code: ​<div onclick=alert('Hi, from outer div!');> <button onclick=alert('Hi, from button!');>Tha button</button>,
I have the following code: foreach (ListItem item in check.Items) { if (item.Selected) {
I've got the following bit of code to check if a form with multiple
I have the following piece of code to check for supported intents. The code

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.