سؤال

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