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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:26:51+00:00 2026-06-18T02:26:51+00:00

I want to catch the latest unhandled error application and redirect it to error

  • 0

I want to catch the latest unhandled error application and redirect it to error page whenever error has occurred. But I got error “No matching route found for RedirectToRoute.” What’s the problem with my code? Here’s my implementation:

Global.asax

routes.MapRoute(
        "ErrorHandler",
        "{ErrorHandler}/{action}/{errMsg}",
       new {controller="ErrorHandler", action = "Index", errMsg = UrlParameter.Optional }
       );

Application_End

 protected void Application_Error(object sender, EventArgs e)
        {
            var strError = Server.GetLastError().Message;
            if (string.IsNullOrWhiteSpace(strError)) return;
            Response.RedirectToRoute("ErrorHandler", new {controller="ErrorHandler", action = "Index", errMsg = strError });
            this.Context.ClearError();
        }

ErrorHandler Controller

public class ErrorHandlerController : Controller
    {

        public ActionResult Index(string errMsg)
        {
            ViewBag.Exception = errMsg;
            return View();
        }

    }

To Test the error handler on my Home Controller

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            //just intentionally added this code so that exception will occur
            int.Parse("test");
            return View();
        }
    }

Updated

typo “contoller”. Thanks to drch. But still I got error “No matching route found for RedirectToRoute.”

  • 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-06-18T02:26:52+00:00Added an answer on June 18, 2026 at 2:26 am

    There must be a problem with your route definitions.

    The route you have:

    routes.MapRoute(
        "ErrorHandler",
        "{ErrorHandler}/{action}/{errMsg}",
       new {controller="ErrorHandler", action = "Index", errMsg = UrlParameter.Optional }
       );
    

    is VERY eager and will cause problems. That’s going to match any url that’s http://yoursite/anything/anything/*. Because your HomeController.Index is even being executed, it means that the routing was already matched with an even more greedy route (perhaps the default one?).

    So there’s 2 things –

    1) you need to move your error handler route up higher. MVC uses the first matching route it finds in the route table.

    2) make your route less greedy, ie:

    routes.MapRoute(
        "ErrorHandler",
        "ErrorHandler/{action}/{errMsg}",
       new {controller="ErrorHandler", action = "Index", errMsg = UrlParameter.Optional }
       );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to catch a fancybox error (The requested content cannot be loaded. Please
-I want to raise an event whenever method showmessage is called.I want to catch
I want to have a 'catch all' route which runs when none of the
I want to catch MediaPlayer errors like this: 01-03 21:03:08.797: E/MediaPlayer(9470): error (1, -2147483648)
I want to catch all exceptions raised (handled or unhandled) to log them. for
I want to catch and ignore and ArrayIndexOutOfBoundsException error (basically it's not something I
I want to catch an error, correct it and continue executing the program. http://jsfiddle.net/Gthv9/12/
I want to catch an IOException Error and want to show it in the
In my app I want to catch reactions from my UITableView but I do
I want to catch the server not responding or timed out error. i was

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.