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.
精彩评论