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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:27:43+00:00 2026-05-13T11:27:43+00:00

I need to globally redirect my users if a custom error is thrown in

  • 0

I need to globally redirect my users if a custom error is thrown in my application. I have tried putting some logic into my global.asax file to search for my custom error and if it’s thrown, perform a redirect, but my application never hits my global.asax method. It keeps giving me an error that says my exception was unhandled by user code.

here’s what I have in my global.

protected void Application_Error(object sender, EventArgs e)
{
    if (HttpContext.Current != null)
    {
        Exception ex = HttpContext.Current.Server.GetLastError();
        if (ex is MyCustomException)
        {
            // do stuff
        }
    }
}

and my exception is thrown as follows:

if(false)
    throw new MyCustomException("Test from here");

when I put that into a try catch from within the file throwing the exception, my Application_Error method never gets reached. Anyone have some suggestions as to how I can handle this globally (deal with my custom exception)?

thanks.

1/15/2010 edit:
Here is what is in // do stuff.

RequestContext rc = new RequestContext(filterContext.HttpContext, filterContext.RouteData);
string url = RouteTable.Routes.GetVirtualPath(rc, new RouteValueDictionary(new { Controller = "Home", action = "Index" })).VirtualPath;
filterContext.HttpContext.Response.Redirect(url, true);
  • 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-13T11:27:43+00:00Added an answer on May 13, 2026 at 11:27 am

    You want to create a customer filter for your controllers / actions. You’ll need to inherit from FilterAttribute and IExceptionFilter.

    Something like this:

    public class CustomExceptionFilter : FilterAttribute, IExceptionFilter
    {
        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext.Exception.GetType() == typeof(MyCustomException))
            {
                //Do stuff
                //You'll probably want to change the 
                //value of 'filterContext.Result'
                filterContext.ExceptionHandled = true;
            }
        }
    }
    

    Once you’ve created it, you can then apply the attribute to a BaseController that all your other controllers inherit from to make it site wide functionality.

    These two articles could help:

    • Filters in ASP.NET MVC – Phil Haack
    • Understanding Action Filters
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to set -Dfile.encoding=UTF8 globally on Windows machine. I tried to set JAVA_OPTS
Need some regular expressions help. So far I have my code working to allow
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
I have a situation where I need to store a globally unique identifier that
i am using .net win forms i need to set some common properties globally
I need to disable delete button GLOBALLY based on some condition? The following solutions
I have a variable that I need globally available throughout my app (so I've
Merry Christmas!!! I've ran into a little issue and I need help. I have
I have a GridView and I need update some data inserting HTML CODE; I
I have a situation where i need to maintain a static variable globally where

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.