문제

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