public string GetRouteUrl(string routeName, string physicalFile, params object[] parames)
        {
            RouteBase routeBase = RouteTable.Routes[routeName];  // GetRouteData(new HttpContextWrapper(HttpContext.Current));
            if (routeBase != null)
            {
                Route route = (Route)routeBase;
                string url = route.Url;
                MatchCollection matchCollection = Regex.Matches(url, @"\w*\{name\d+\}\w*");
                string[] names = physicalFile.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < matchCollection.Count; i++)
                {
                    url = Regex.Replace(url, @"\w*\{name" + i + @"\d*\}\w*", names[i]);
                }
                url = Regex.Replace(url, @"\w*\{param\}\w*", parames[0].ToString());

                return "/"+url;
            }
            return null;
        }
public static void RegisterRoutes(RouteCollection routes)
        {
            routes.MapPageRoute("Default", "", "~/Index.aspx");
            routes.MapPageRoute(
           "User",
           "{name0}/{name1}",
           "~/view/{name0}/{name1}.aspx"
           , false);

            routes.MapPageRoute(
           "User2",
           "{name0}/{name1}/{param}",
           "~/view/{name0}/{name1}.aspx"
           , false);
        }

相关文章:

  • 2021-07-27
  • 2021-07-30
  • 2021-11-01
  • 2021-11-13
  • 2021-05-20
  • 2021-05-18
  • 2021-09-16
猜你喜欢
  • 2021-09-03
  • 2022-01-21
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2021-08-13
相关资源
相似解决方案