After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home Controller

Solved! So, we need to add a route contraint to the webforms route to ensure that it only catches on incoming routes, not outgoing route generation.

Add the following class to your project (either in a new file or the bottom of global.asax.cs):

public class MyCustomConstraint : IRouteConstraint{
    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection){
        return routeDirection == RouteDirection.IncomingRequest;
    }
}

Then change the Tickets route to the following:

routes.MapPageRoute(
    "Tickets",
    "Reports/Tickets",
    "~/WebForms/Reports/Tickets.aspx",
    true, null, 
    new RouteValueDictionary { { "outgoing", new MyCustomConstraint() } }
);

Leave a Comment