简体   繁体   中英

GET parameter after routing with RouteTable

I am using RouteTable 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM