Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding asp.net routing in webform & Asterisk sign

I saw people use asterisk sign at the time of routing in webform. i just do not understand the importance of Asterisk sign like below one

routes.MapPageRoute(
  "View Category",               // Route name
  "Categories/{*CategoryName}",  // Route URL
  "~/CategoryProducts.aspx"      // Web page to handle route
);

what is the meaning of asterisk sign and also tell me what kind of situation i should use asterisk sign like above.

"Categories/{*CategoryName}"

it would be better if anyone come with small sample code of using Asterisk sign just to show the importance & use of asterisk sign in real life apps.

like image 988
Keith Costa Avatar asked Sep 25 '11 10:09

Keith Costa


1 Answers

Since this was the first resource Google returned me for variable number of parameters I added below example from MSDN so future readers would find the solution here.

The following example shows a route pattern that matches an unknown number of segments.

query/{queryname}/{*queryvalues}

Case 1

URL :
/query/select/bikes/onsale

Resolved Parameter Values:

  • queryname = "select"
  • queryvalues = "bikes/onsale"

Case 2

URL :
/query/select/bikes

Resolved Parameter Values:

  • queryname = "select"
  • queryvalues = "bikes"

Case 3

URL :
/query/select

Resolved Parameter Values:

  • queryname = "select"
  • queryvalues = Empty string

Reference: MSDN: Handling a Variable Number of Segments in a URL Pattern

like image 98
Menol Avatar answered Oct 11 '22 17:10

Menol