在 global.asax
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Products","Products/{id}/{productname}",
"~/productdetails.aspx");
}
在 products.aspx 中
<ahref='<%#string.Format("/Products/{0}/{1}",Eval("id"),Clean.CleanUrl(Eval("ProductName").ToString())) %>'><%# Eval("ProductName") %></a>
在 productsdetails.aspx.cs 中
if (!IsPostBack)
{
if (RouteData.Values["id"] != null)
{
loadproduct();
}
}
void loadproduct()
{
select ............. where id= RouteData.Values["id"].ToString();
}
这是清洁班
public static class Clean
{
public static string CleanURL(this string kelime)
{
if (kelime == "" || kelime == null) { return ""; }
kelime = kelime.Replace("ş", "s");
kelime = kelime.Replace("Ş", "S");
kelime = kelime.Replace(".", "");
kelime = kelime.Replace(":", "");
kelime = kelime.Replace(";", "");
kelime = kelime.Replace(",", "");
kelime = kelime.Replace(" ", "-");
kelime = kelime.Replace("!", "");
kelime = kelime.Replace("(", "");
kelime = kelime.Replace(")", "");
kelime = kelime.Replace("'", "");
kelime = kelime.Replace("ğ", "g");
kelime = kelime.Replace("Ğ", "G");
kelime = kelime.Replace("ı", "i");
kelime = kelime.Replace("I", "i");
kelime = kelime.Replace("ç", "c");
kelime = kelime.Replace("ç", "C");
kelime = kelime.Replace("ö", "o");
kelime = kelime.Replace("Ö", "O");
kelime = kelime.Replace("ü", "u");
kelime = kelime.Replace("Ü", "U");
kelime = kelime.Replace("`", "");
kelime = kelime.Replace("=", "");
kelime = kelime.Replace("&", "");
kelime = kelime.Replace("%", "");
kelime = kelime.Replace("#", "");
kelime = kelime.Replace("<", "");
kelime = kelime.Replace(">", "");
kelime = kelime.Replace("*", "");
kelime = kelime.Replace("?", "");
kelime = kelime.Replace("+", "-");
kelime = kelime.Replace("\"", "-");
kelime = kelime.Replace("»", "-");
kelime = kelime.Replace("|", "-");
kelime = kelime.Replace("^", "");
return kelime;
}
}