ASP.NET 4.0 新技術 - Routing
想要有rest的功能不能錯過Routing技術
1.先加入Global.asax並修改程式碼如下
using System.Web.Routing
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new Route("Category/{action}/{categoryName}"
, new PageRouteHandler("~/WebForm1.aspx")));
}
2.這樣就可以在WebForm1.aspx中取得資料
protected void Page_Load(object sender, EventArgs e)
{
string action,cName;
if(Page.RouteData.Values["action"] != null)
action = Page.RouteData.Values["action"].ToString();
if(Page.RouteData.Values["categoryName"] != null)
cName = Page.RouteData.Values["categoryName"].ToString();
}
3.記得測試用網址是
http://localhost:XXXX/Category/aaaaa/cName
1.先加入Global.asax並修改程式碼如下
using System.Web.Routing
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new Route("Category/{action}/{categoryName}"
, new PageRouteHandler("~/WebForm1.aspx")));
}
2.這樣就可以在WebForm1.aspx中取得資料
protected void Page_Load(object sender, EventArgs e)
{
string action,cName;
if(Page.RouteData.Values["action"] != null)
action = Page.RouteData.Values["action"].ToString();
if(Page.RouteData.Values["categoryName"] != null)
cName = Page.RouteData.Values["categoryName"].ToString();
}
3.記得測試用網址是
http://localhost:XXXX/Category/aaaaa/cName
留言