Asp.net网址重写问题

时间:2010-09-30 09:14:54

标签: asp.net url-rewriting

Global.asax代码

protected void Application_BeginRequest(object sender, EventArgs e)
{
 string fullOrigionalpath = Request.Url.ToString();

 if (fullOrigionalpath.Contains("/Form/Electronic/Led"))
 {
  Context.RewritePath("/Form/Handler.aspx?Id=Led&cat=Electronic");
 }
}

如何制作网址地图?

Url: /Form/Car/Mercedes
Map: /Form/Handler.aspx?Id=Mercedes&cat=Car

Url: /Form/Animals/Cat
Map: /Form/Handler.aspx?Id=Cat&cat=Animals

1 个答案:

答案 0 :(得分:1)

string fullOriginalPath = Request.Url.AbsolutePath;
if(fullOriginalPath.StartsWith("/Form/"))
{
  string[] parts = fullOriginalPath.Substring(6).Split('/');
  if(parts.Length == 2)
  Context.RewritePath("/Form/Handler.aspx?Id=" + parts[0] + "&cat=" + parts[1]);
}