Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7676295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:10:04+00:00 2026-05-31T17:10:04+00:00

I have the following setup: Web.config has customErrors mode=Off Global.Application_Error() event calls a custom

  • 0

I have the following setup:

  1. Web.config has customErrors mode=”Off”
  2. Global.Application_Error() event calls a custom function called UtilitiesWeb.ProcessError()
  3. UtilitiesWeb.ProcessError() logs the error, then redirects the user with: HttpContext.Current.Response.Redirect(defaultErrorPage, false)

This works well as a good global error handler, except when dealing with AJAX. AJAX displays the error with in JavaScript, and ignores the redirect.

To get the page to redirect on an AJAX error I had to do the following:

  1. Update asp:ScriptManager to: <asp:ScriptManager ID=”scriptmanager1″ runat=”server”
    OnAsyncPostBackError=”ScriptManager1_AsyncPostBackError”>
  2. Add Server side ScriptManager1_AsyncPostBackError method that calls UtilitiesWeb.ProcessError()
  3. Add the following JavaScript to redirect because AJAX ignores the server side redirect:
<script type="text/javascript">
if (typeof (Sys) != 'undefined') {
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
   function endRequest(sender, e) {
        if (e.get_error()) {
           window.location = "ErrorPage.aspx"
        }
    }
 }
 </script>

But all this seems like a workaround. Is there way to have a server side redirect that works with AJAX errors?

For completeness, here is the code for UtilitiesWeb.ProcessError():

public static void ProcessError()
{
    string defaultErrorPage = ConfigurationManager.AppSettings["DefaultErrorPage"];
    string displayError = ConfigurationManager.AppSettings["DisplayError"];
    Exception ex;

    if (!string.IsNullOrWhiteSpace(displayError))
        displayError = displayError.ToLower();

    ex = HttpContext.Current.Server.GetLastError();

    if (ex != null)
        Log.LogException(DateTime.Now, null, ex);

    // Redirect to Default Error page on error
    if (displayError == "basic")
    {
        HttpContext.Current.Server.ClearError(); // needed for redirect to work

        if (!string.IsNullOrWhiteSpace(defaultErrorPage))
            HttpContext.Current.Response.Redirect(defaultErrorPage, false); // doesn't work with AJAX calls
    }
}  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:10:05+00:00Added an answer on May 31, 2026 at 5:10 pm

    When you’re making an AJAX request, you just get a response containing some kind of data, which is interpreted by scripts on the client side.

    So, in case on error, the only thing that the server can do is send the error in the response to the ajax request.

    At this moment, the client-side script receives the error information and you can use it the way you like. You’re doing it the right way.

    However, if you need to take some extra actions, like logging the error, you have two options:

    1) send the error back to the server from the javascript: for example you could use aregular form with an input of type hidden, set the input value, and post the form using form.submti() to your error page. Your page can recover the contents of the hidden field using the Page’s Request object and process it.

    2) catch the error on server side, within try/catch, or page_error or application_error events, log the exception, or whatever you want to do with it, and throw a new exception that will arrive at the client side, hiding the original exception info.

    The second option is cleaner and safer, as you don’t send error information to the browser.

    Think that the server can’t redirect the browser in any way because when the server is sending a reponse to an AJAX request the server isn’t rendering a new page for the browser,and the browser is not receiving a new whole page. The server is simply sending some information to be processed by client-side scripts. So your script is responsible for reloading a new page or whatever you need to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following setup in my web.config (within system.webSever tag) to compress components
In my Web.config file have the following setup: <add key=ClientMail value=ridermansb@bindsolution.com/> In my file
I have the following setup: ASP.net 3.5 Web Site Project C# Class Library with
I have the following code in a web.config file of the default IIS site.
I have following setup, but when I put 1024 and replace all 512 with
I have the following setup: Code on my local machine (OS X) shared as
I have a following setup: App - Magnolia site running under Tomcat 6.0.16 ISAPI
I have the following setup, and I need to know how to persist state.
I have the following setup, and the empty view text doesn't show up... protected
I have the following setup: eclipse a standard Java project (A) an eclipse plugin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.