开发者

GET parameter after routing with RouteTable

I am using R开发者_如何学GoouteTable from System.Web.Routing for routing.

RouteTable.Routes.MapPageRoute("gallery-handler", "Gallery/1234.ashx", "~/Handlers/Gallery.aspx?id=1234");

How can i access GET parameter (id) in Page.


In your example you have hardcoded the ID, so this route will only work for 1234. But if you write the route with a dynamic route value:

RouteTable.Routes.MapPageRoute(
  "gallery-handler", 
  "Gallery/{id}.ashx", 
  "~/Handlers/Gallery.aspx");

then you should be able to retrieve the id parameter in Gallery.aspx.cs:

Request.RouteData["id"]

So the id parameter is already in the URL, and the 'rewrite' to Gallery.aspx doesn't actually need the parameter in the URL, because ASP.NET will save it for you in the Request.RouteData collection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜