这件事让我很生气:
浏览器网址------->物理路径
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
其中anypage.aspx是任何aspx页面
任何文件夹都是任何路径
我正在使用这条路线:
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() } });
它是一个经典的asp.net网站,而不是MVC
加载了UrlRoutingModule的IIS 7集成模式
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
答案 0 :(得分:0)
在路线前添加
RouteTable.Routes.MapPageRoute("Alias", "{pollName}/{*url}", "~/{url}", true, new RouteValueDictionary{{"url","Default.aspx"}}, new RouteValueDictionary { { "pollName", sb.ToString() } });
我想要处理的每条路径的路线:
//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() } });