2014-06-28 104 views
0

我有幾個dinamically生成的網址,如http://localhost:35228/begineercontent?name=lanaguages&id=23,我用路由來隱藏.aspx擴展名,現在我想看到上面的url這樣http://localhost:35228/begineercontent/lanaguages/23我嘗試了幾次從iis網址的URL重寫方法改寫工具沒有任何工作請善待請幫助我在asp.net中動態生成的網址的url重寫

回答

0

這可以做到很容易。您需要在global.asax中更改/添加此代碼。

void registerroute(RouteCollection routes) 
{ 

     routes.MapPageRoute("begineercontent", "begineercontent/languages/{Id}", "~/begineercontent.aspx"); 
} 

void Application_Start(object sender, EventArgs e) 
{ 
      // Code that runs on application startup 
      registerroute(RouteTable.Routes); 
} 

您還需要通過添加

using System.Web.Routing 

在你begineercontent.aspx您需要將此代碼添加到頁面加載功能,包括在Global.asax中正確的裝配。關於如何使用路由工作

var Id=(Page.RouteData.Values["Id"] as string); 

更的相關詳細的教程可以在這裏找到:
http://msdn.microsoft.com/en-us/library/vstudio/cc668177%28v=vs.100%29.aspx

+0

我照你說的,但沒有在URL @ user3786513無差異 –