Asp.net URL rooting configuration

mybwu_com發表於2014-01-06

URL Mapping :

Web Config :


<configuration>
<system.web>
<urlMappings enabled="true">
<add url="./Category.aspx"
mappedUrl="./Default.aspx?category=default"/>
<add url="./Software.aspx"
mappedUrl="./Default.aspx?category=software"/>
</urlMappings>

//add more ...

</system.web>
</configuration>


URL rooting

In global file :


void Application_Start(object sender, EventArgs e)
{

RouteTable.Routes.MapPageRoute("product-details",
"product/{productID}","~/productInfo.aspx");

RouteTable.Routes.MapPageRoute("products-in-category",
"products/category/{categoryID}","~/products.aspx");

}


Retrieve parameter from query string :

protectedvoid Page_Load(object sender, EventArgs e)
{
stringproductID = (string)Page.RouteData.Values["productID"];
lblInfo.Text= "You requested " + productID;
}


相關文章