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 703453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:49:58+00:00 2026-05-14T03:49:58+00:00

All, I’m learning MVC and using it for a business app (MVC 1.0). I’m

  • 0

All,

I’m learning MVC and using it for a business app (MVC 1.0).

I’m really struggling to get my head around exception handling. I’ve spent a lot of time on the web but not found anything along the lines of what I’m after.

We currently use a filter attribute that implements IExceptionFilter. We decorate a base controller class with this so all server side exceptions are nicely routed to an exception page that displays the error and performs logging.

I’ve started to use AJAX calls that return JSON data but when the server side implementation throws an error, the filter is fired but the page does not redirect to the Error page – it just stays on the page that called the AJAX method.

Is there any way to force the redirect on the server (e.g. a ASP.NET Server.Transfer or redirect?)

I’ve read that I must return a JSON object (wrapping the .NET Exception) and then redirect on the client, but then I can’t guarantee the client will redirect… but then (although I’m probably doing something wrong) the server attempts to redirect but then gets an unauthorised exception (the base controller is secured but the Exception controller is not as it does not inherit from this)

Has anybody please got a simple example (.NET and jQuery code). I feel like I’m randomly trying things in the hope it will work

Exception Filter so far…

public class HandleExceptionAttribute : FilterAttribute, IExceptionFilter
{
    #region IExceptionFilter Members

    public void OnException(ExceptionContext filterContext)
    {
        if (filterContext.ExceptionHandled)
        {
            return;
        }

        filterContext.Controller.TempData[CommonLookup.ExceptionObject] = filterContext.Exception;

        if (filterContext.HttpContext.Request.IsAjaxRequest())
        {
            filterContext.Result = AjaxException(filterContext.Exception.Message, filterContext);
        }
        else
        {
            //Redirect to global handler
            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = AvailableControllers.Exception, action = AvailableActions.HandleException }));
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
        }
    }

    #endregion

    private JsonResult AjaxException(string message, ExceptionContext filterContext)
    {
        if (string.IsNullOrEmpty(message))
        {
            message = "Server error";   //TODO: Replace with better message
        }

        filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
        filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;       //Needed for IIS7.0

        return new JsonResult
        {
            Data = new { ErrorMessage = message },
            ContentEncoding = Encoding.UTF8,
        };
    }
}
  • 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-14T03:49:58+00:00Added an answer on May 14, 2026 at 3:49 am

    I use the OnFailure hanlder in Ajax.Beginform(). The client-side failure handler can redirect by setting window.location (among a number of other options.) This will work in 99% of modern browsers- if the browser supports AJAX it should support this.

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

Sidebar

Related Questions

All the examples I've come across using Google Maps API seem to show a
All of the examples I've seen of using yield return x; inside a C#
All I want is to get the website URL. Not the URL as taken
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
All, I am building a small site using PHP. In the site, I receive
All, I'm using wordpress with this and for some reason the eventDrop stopped working.
All, I'm using Facebook Connect (JS SDK) to authenticate a user to my site.
We're building an app, our first using Rails 3, and we're having to build
All I am trying to create an app that start capturing the video from
All the examples I see for doing a query show only using one key.

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.