How to access QueryString parametr if I use Routing

169 views Asked by At

I use ASP.NET Routing for pretty URLs, but I cant access QueryStringParameters (only RouteData value). I am using the routing with Web Forms.

Here is example of my RegisterRoutes (Global.asax):

routes.MapPageRoute("Catalog", "{language}/catalog/", "~/Pages/Catalog.aspx?step=1");

I use this code for accessing parameter "step" in Catalog.aspx page:

string value = Request.QueryString["step"];

But it returns null.

How can I access QueryString parameter "step" if I don't want toget it from RouteData?

1

There are 1 answers

0
Elim Garak On

Use GetFreindlyURLSegement. You may need to get the NuGet package (if you do not have it already) Micorsoft.AspNet.FriendlyURLs

var Segment = Request.GetFriendlyUrlSegments().ToList();
if (Segment.Count <= 0)
{
    return;
}

string param1 = Segment[0].ToString();
string param2 = Segment[1].ToString();