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

后端 未结 1 1401
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 00:48

I\'m trying to route a .aspx (webforms page) in my asp.net mvc project. I register the page in global.asax:

routes.IgnoreRoute(\"{resource}.axd/{*pathInfo}\"         


        
相关标签:
1条回答
  • 2020-12-02 00:56

    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() } }
    );
    
    0 讨论(0)
提交回复
热议问题