lng
lng

Reputation: 805

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.

Upvotes: 1

Views: 1517

Answers (1)

Michiel van Oosterhout
Michiel van Oosterhout

Reputation: 23084

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.

Upvotes: 1

Related Questions