This thing is driving me mad:

browser url -------> phisical path

http://somedomain/routeName ----> ~/Default.aspx WORKS

http://somedomain/routeName/anypage.aspx ----> ~/anypage.aspx  WORKS

http://somedomain/routeName/anyfolder ----> ~/anyfolder/Default.aspx DOESNT WORK

http://somedomain/routeName/anyfolder/anypage.aspx ----> ~/anyfolder/anypage.aspx WORKS

where anypage.aspx is any of the aspx pages

where anyfolder is any path

i'm using this route:

var sb = new StringBuilder("(");
foreach (Poll item in DataProvider.Get<IPollProvider>().GetAll())
{
    sb.AppendFormat("{0}|", item.Name);
}
sb.Length--;
sb.Append(")");
RouteTable.Routes.MapPageRoute("Alias", "{pollName}/{*url}", "~/{url}", true, new RouteValueDictionary{{"url","~/Default.aspx"}}, new RouteValueDictionary { { "pollName", sb.ToString() } });

it is a classic asp.net site, not MVC

IIS 7 integrated mode with UrlRoutingModule loaded

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
有帮助吗?

解决方案

i found a way:

add before the route

RouteTable.Routes.MapPageRoute("Alias", "{pollName}/{*url}", "~/{url}", true, new RouteValueDictionary{{"url","Default.aspx"}}, new RouteValueDictionary { { "pollName", sb.ToString() } });

a route for every path i want to handle:

//for http://somedomain/routeName/admin

RouteTable.Routes.MapPageRoute("AliasAdmin", "{pollName}/Admin/{*url}", "~/Admin/{url}", true, new RouteValueDictionary{{"url","Default.aspx"}}, new RouteValueDictionary { { "pollName", sb.ToString() } });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top