混合 WebForms 和 MVC5 路由不起作用
Mixing WebForms and MVC5 routing not working
我有以下用于 Web 表单和 MVC 路由的代码。
MVC 路由似乎工作正常,但当我混合使用两者时 Web 表单却不行。
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("");
//MVC
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
//WebForms
routes.MapPageRoute(
"myPage",
"page/companyInfo/{*queryvalues}",
"~/company/details.aspx"
);
我需要为 details.aspx 页面编写 IgnoreRoute 语句吗?
更改路由的顺序,MVC路由应该在底部,因为默认基本上是包罗万象的。 MVC 从上到下处理路由,如果找到匹配项,它将停止查找并将您路由到匹配的路由。
//WebForms
routes.MapPageRoute(
"myPage",
"page/companyInfo/{*queryvalues}",
"~/company/details.aspx"
);
//MVC
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
我有以下用于 Web 表单和 MVC 路由的代码。
MVC 路由似乎工作正常,但当我混合使用两者时 Web 表单却不行。
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("");
//MVC
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
//WebForms
routes.MapPageRoute(
"myPage",
"page/companyInfo/{*queryvalues}",
"~/company/details.aspx"
);
我需要为 details.aspx 页面编写 IgnoreRoute 语句吗?
更改路由的顺序,MVC路由应该在底部,因为默认基本上是包罗万象的。 MVC 从上到下处理路由,如果找到匹配项,它将停止查找并将您路由到匹配的路由。
//WebForms
routes.MapPageRoute(
"myPage",
"page/companyInfo/{*queryvalues}",
"~/company/details.aspx"
);
//MVC
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);