【发布时间】:2014-04-04 15:28:27
【问题描述】:
我在 ASP.NET 4.5 中成功使用了“友好 URL”模块
在路由配置中我可以添加这样的路由:
routes.MapPageRoute("mypage", "mypage/{mypageName}", "~/mypage.aspx");
对于这样的网址:
mysite.com/mypage/hello
在“mypage.aspx”页面中,我可以得到这样的 URL 段:
using Microsoft.AspNet.FriendlyUrls;
// Get URL segments
IList<string> segments = Request.GetFriendlyUrlSegments();
if (segments.Count > 0)
{
// Get first segment
string url = segments[0];
}
但是,我无法让这适用于根 URL。例如'我的 site.com/ttee'
我想获取 'ttee' 并将其传递到页面中。但是 'Request.GetFriendlyUrlSegments()' 为根返回 0。
我怎样才能做到最好?
【问题讨论】:
标签: asp.net friendly-url