Failing to catch ASP.Net Server error in sharepoint
I have an asp.net control that contains a grid view sitting on top of an Ajax update panel. The control has been added to a shar开发者_运维技巧epoint page. When a button is clicked, some server code is called to store the contents of the grid.
If the server code throws an error, I want to spit out a javascript alert displaying the error message, but for some reason the error that bubbles up from the server is the generic 500 server error, which doesn't contain any details of the original error.
Can anyone explain why this is?
Many thanks Gerry
The default behaviour of ASP.NET (and SharePoint) is to display a generic error page when an exception is thrown. For security reasons, this page hides all details of the error. With debug settings in web.config you can get a stack trace, but that won't give you something easily manipulated in javascript.
To return a custom error page you can either set up a global unhandled exception handler (probably overkill for this) or you can catch the exception and modify the response appropriately. For a rest method you would clear the response, set status to 500 and write the error message to the response. For an UpdatePanel, you would render the panel as an error message or with script to show the alert. Not sure if you would set status in this case - UpdatePanel is an ugly hack to fake true ajax in webforms, so you can't expect the code to be particularly clean.
精彩评论