Im using Google Analytics D开发者_StackOverflowashboard 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#
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.
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.
The error is server-side so should actually try to fix it in your code.
精彩评论