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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:58:26+00:00 2026-06-13T16:58:26+00:00

I have a asp.net mvc 3 application with IIS7 and IIS express on local,

  • 0

I have a asp.net mvc 3 application with IIS7 and IIS express on local, which is using Application_Error for logging the exceptions and redirecting to a custom error page. My application has different regions, and the application_error is called whenever the controller or the action is not matched, but not for the region.

Here is an example of the routes used:

routes.MapRoute(
            "Default",
            "{region}/{controller}/{action}/{id}",
            new { region = "uk", controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
            new { region = new RegionWhitelistConstraint() } // constraint for valid regions
        );

In this case the Application_Error would be fired for /uk/NotFoundPage but not for /foo/Home

Here the constraint for the region:

public class RegionWhitelistConstraint : IRouteConstraint
{
    public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        var whiteList = Region.DefaultWhiteList;
        var currentRegionValue = values[parameterName].ToString();
        return whiteList.Contains(currentRegionValue);
    }
}

I have seen this question, that propose adding a catch all route, but apart from that I would like to know if there is a way of firing Application_Error as it is done for the controllers or actions.

  • 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-13T16:58:27+00:00Added an answer on June 13, 2026 at 4:58 pm

    I figured out what was the problem: when a controller or an action is wrong they are still matched by the route system with the pattern:

            routes.MapRoute(
                "Default",
                "{region}/{controller}/{action}/{id}",
                new { region = "uk", controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
                new { region = new RegionWhitelistConstraint() } // constraint for valid regions
            );
    

    but when the region is not in the whitelist it is not matched. This makes bypass the application_error. The solution that I have used is creating a catchall route:

            routes.MapRoute(
                "NotFound",
                "{*url}",
                new { region = "uk", controller = "Error", action = "NotFound", id = UrlParameter.Optional }
            );
    

    and an action that raises an HttpException:

        [HttpGet]
        public ActionResult NotFound()
        {
            throw new HttpException(404, "Page not found");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7
I have an ASP.NET MVC 3 application (in IIS 7.5) with a portable area.
I have an ASP.NET MVC application using Authorization Attributes on Controllers and Actions. This
I have a ASP.NET MVC application using NHibernate and the application runs fine when
I have a ASP.NET MVC application that runs in both IIS 6 and 7.
I have an ASP.Net MVC application and I'm using Forms authentication in SQL Server.
I have an Asp.Net MVC 2 web application deployed on IIS 7.5 on .Net
I have an asp.net mvc 2 application which works fine when run from visual
I have a strange issue with an Asp.NET MVC application. Using Asp.NET MVC 3
I have an ASP.NET MVC 3 application with a auto-authorization using the client's windows

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.