Fraz Sundal
Fraz Sundal

Reputation: 10448

How to catch 500 internal server error in c#

Im using Google Analytics Dashboard Control which are available at

http://gadashboardcontrols.codeplex.com/

Issue is its working fine when im connected to internet but if im using it on a machine that doesnt have internet access then it shows

Server Error in '/' Application.
The remote name could not be resolved: 'www.google.com' 

I want to catch this exception and shows a friendly message to user. Im calling these dashboard control on my View in an iframe like this

<iframe src="../../GoogleAnalytics/Visitor.aspx" height="275"></iframe>

and if i place try catch in Visitor.aspx page it doesnot catch the exception. How should i catch this exception, Im using asp.net mvc 2 with c#

Upvotes: 0

Views: 3745

Answers (3)

Gustavo Puma
Gustavo Puma

Reputation: 1055

The error is server-side so should actually try to fix it in your code.

Upvotes: 0

Liam
Liam

Reputation: 1768

What you can do instead is check network connectivity and serve alternate content in the page if the user is offline. Look into System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() for this.

There's no good way to catch this exception since you're using an iframe and the page is loaded in the browser and not via code. There are some tricks for this, but not as reliable.

Upvotes: 0

Pieter van Ginkel
Pieter van Ginkel

Reputation: 29632

You cannot catch this exception because the problem occurs in the browser and not on the server. You do not have control over this from the aspx code.

Upvotes: 1

Related Questions