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

  • Home
  • SEARCH
  • 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 3457444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:51:39+00:00 2026-05-18T09:51:39+00:00

My Question: Does a HttpWebResponse.StatusCode detect Asp.Net errors? Mainly a yellow screen of death?

  • 0

My Question:
Does a HttpWebResponse.StatusCode detect Asp.Net errors? Mainly a yellow screen of death?

Some Background:
I am working on a simple c# console app that will test servers and services to make sure they are still functioning properly. I assumed since the HttpStatusCodes are enumerated with OK, Moved, InteralServerError, etc… that I could simply do the following.

WebRequest request = WebRequest.Create(url);
request.Timeout = 10000;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (response == null || response.StatusCode != HttpStatusCode.OK)
{
   // SERVER IS OK
   return false;
}
else
{
   // SERVER HAS SOME PROBLEMS
   return true;
}

I found out this morning however that this doesn’t work. An ASP.Net application crashed showing a Yellow Screen Of Death and my application didn’t seem to mind because the response.StatusCode equaled HttpStatusCode.OK.

What am I missing?

Thanks
// lance

Update
Thanks to Jon this seems to be working.

 HttpWebResponse response;
 try
 {
   response = (HttpWebResponse)request.GetResponse();
 }
 catch (WebException webexp)
 {
   response = (HttpWebResponse)webexp.Response;
 }
  • 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-18T09:51:40+00:00Added an answer on May 18, 2026 at 9:51 am

    GetResponse will throw a WebException for errors – but you can catch the WebException, use WebException.Response to get the response, and then get the status code from that.

    As far as I’m aware, GetResponse never returns null, so you can remove that test from your code.

    Also, rather than having if/else blocks to return true/false, it’s simple just to return the result of evaluating an expression, for example:

    return response.StatusCode == HttpStatusCode.OK;
    

    (To be honest, you could probably return false if any WebException is thrown…)

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

Sidebar

Related Questions

Question: Does Informix have a construct equivalent to Oracle's materialized view or is there
Maths101 question - does anyone know how to calculate an ellipse (width/height) that will
I hope this question does not come off as broad as it may seem
I have this question: Does implementing a custom MembershipProvider class needs you to implement
This might be a silly question: Does HTTP ever use the User Datagram Protocol?
This question was inspired by a similar question: How does delete[] know the size
This is a self-explanatory question: Why does this thing bubble into my try catch's
This might be a old question: Why does IEnumerable<T> inherit from IEnumerable ? This
Based on the response to this question: Why does C++ have header files and
Ok, I've read the Stack Overflow question 'What does it mean to program to

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.