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?
Config.RootUrl + "/Dashboard/Default.aspx"in the same server/application?