How to route a .aspx page in asp.net mvc 3 project?

后端 未结 4 1444
陌清茗
陌清茗 2020-12-01 10:02

I have a .aspx page in the following path:

Areas/Management/Views/Ticket/Report.aspx

I want to route that to the following path in my brows

4条回答
  •  攒了一身酷
    2020-12-01 10:24

    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 MyCustomConstaint : 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 MyCustomConstaint() } }
    );
    

提交回复
热议问题