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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:48:39+00:00 2026-06-07T17:48:39+00:00

I have some code to display a button if a URL exists: try {

  • 0

I have some code to display a button if a URL exists:

try
{
    string dashboardURL = Config.RootUrl + "/Dashboard/Default.aspx";
    WebRequest req = WebRequest.Create(dashboardURL);
    WebResponse response = req.GetResponse();
    btnDashboard.Visible = true;
}
catch (Exception)
{
    btnDashboard.Visible = false;
}

However, when debugging, req.getResponse() causes Application_Error to fire. I checked the exception being caught here and it is a System.Net.WebException. My understanding was that Application_Error is fired for unhandled exceptions.

If I change the code to force an exception as follows:

try
{
    string dashboardURL = Config.RootUrl + "/Dashboard/Default.aspx";
    WebRequest req = WebRequest.Create(dashboardURL);

    int j = 0;
    int i = 1 / j;

    WebResponse response = req.GetResponse();
    btnDashboard.Visible = true;
}
catch (Exception)
{
    btnDashboard.Visible = false;
}

then Application_Error is not fired, which is good. Is there something particular about handling errors with GetResponse() that always causes Application_Error to fire, even if the exception is handled?

  • 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-07T17:48:41+00:00Added an answer on June 7, 2026 at 5:48 pm

    Is the /Dashboard/Default.aspx in the same server/application?

    If so then processing of that request can cause an error that will be captured by the Application_Error. The reason is that by doing GetResponse() you are doing a HTTP request, and any exceptions that happen while processing the request on (potentially) remote server will not be handled by try/catch on the calling code. In your special case remote server = local server, but the idea does not change.

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

Sidebar

Related Questions

I have some code to display a like button and this shows but with
I have some code to display a long list of languages inside Rails form
I have written some code to display a YouTube video on my page but
I have some validation code which should display the max / min of a
I'have written a simple code, that gets accelerometer&orientation meter and display some graphics based
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have some code that will change the background color of a specific label
I have some code here that uses bitsets to store many 1 bit values
I have some code that is supposed to return an NSString. Instead it is

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.