简体   繁体   中英

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#

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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM