This article covers the case when you are using Telerik RadAjax and you have set custom errors on in your web.config. When an error is thrown somewhere in your code, the page normally displays an javascript alert box stating that an Unexpected ajax response was received from the server. You need to ensure that this will not happen and the page will throw the error and let the .NET runtime bubble this error up to the global.asax file so the user gets redirected to the error page as set in the web.config file.
The server actually redirects to the custom error page. The browser handles that transparently (there is no way for client-side code to detect a redirect in an AJAX request) and then returns the custom error page. You should be able to confirm that with tools like Fiddler and the Firebug Firefox extension. Now the client-side code detects unexpected content and throws the error that you will see.
The solution to this would be to edit your custom error page, so that it sets the Response.RedirectLocation property to its own URL. This way, normal post-back requests will not be redirected - the server will return a 200 status code, instead of 300. AJAX requests will still have the Location HTTP header that will get picked up by Telerik RadAjax and it will redirect to the custom error page. That page will be loaded with a normal GET request and you can display the error to the user accordingly.
Generally speaking Response.RedirectLocation needs to be set unconditionally inside the OnInit event of the ErrorPage.
| C# |
Copy Code |
|
protected override void OnInit(EventArgs e) { Response.RedirectLocation = "Error.aspx"; base.OnInit(e); } |