比方说我有这样的SQL Server表:Asp.net路由网址转换?
id Name Band
--------------------
1 John Beatles
2 Paul Beatles
3 George Beatles
4 Ringo Beatles
5 Jim Doors
我想有一个人详细信息页面,如:
http://localhost/Music/Beatles/Paul
,我想对待是:
http://localhost/Details.aspx?id=2
所以,我正在写这个代码来注册一个简单的路线:
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("MyRoute", "Music/{Band}/{Name}", "~/Details.aspx");
}
但我不明白:
当Asp.net得到http://localhost/Music/Beatles/Paul
,如何没有他知道知道,保罗的价值是2
?
你是否告诉我,每当asp.net遇到Paul
他应该去DB和扫描预定义的唯一列(在这种情况下为Name
),并得到它的列ID
值?
或者我应该注入保罗的值到URL,像这样做:
http://stackoverflow.com/questions/13938994/jquery-conditional-validation-based-on-select-text
^
|
---------------------------------------
这将是我的情况:
http://localhost/Music/Beatles/2/Paul
你应该看看AttributeRouting的代码示例。 https://github.com/mccalltd/AttributeRouting –