I have, in Application_Start of global.asax

    routes.MapPageRoute("Route2", "public/{folder2}/{folder1}/{page}", "~/userpage.aspx", true);
    routes.MapPageRoute("Route1", "public/{folder1}/{page}", "~/userpage.aspx", true);
    routes.MapPageRoute("Route0", "public/{page}", "~/userpage.aspx", true);

So each file (without extension) located in

  • public/folder2/folder1
  • public/folder1
  • public

is mapped to ~/userpage.aspx.

Can I use only one rule so as to include other paths such as

  • public/{folder4}/{folder3}/{folder2}/{folder1}/{page}
  • public/{folder3}/{folder2}/{folder1}/{page}

that will be mapped to ~/userpage.aspx?

有帮助吗?

解决方案

You can use a catch all parameter. A catch all parameter is defined by adding * character at the beginning of the parameter name. It could be used only at the end of the route definition and it will catch the raw url string with slashes.

In your example it means that you will have to parse {page} parameter manually from the RouteData object.

routes.MapPageRoute("Route0", "public/{*fullpath}", "~/userpage.aspx", true);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top