URL Routing C# mvc and Web Forms

前端 未结 2 1266
心在旅途
心在旅途 2021-01-27 09:42

So I have a webforms and an mvc application combined and am trying to get things routed correctly. I have the default routing working as expected, but when I click on an actionl

2条回答
  •  梦毁少年i
    2021-01-27 10:18

    I ended up having to add a routing constraint. Here's what I ended up doing.

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
              routes.MapPageRoute("",
                   "", "~/Default.aspx", true, null, new RouteValueDictionary { { "outgoing", new PageConstraint() } });
    
    
                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Chips", action = "Index", id = UrlParameter.Optional }
                );
    

    And the page constraint.

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

提交回复
热议问题