11

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.

Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47
Keith Costa
  • 1,783
  • 11
  • 35
  • 68
  • "Astrix"? Is this via google translate? :) The [star](http://en.wikipedia.org/wiki/Asterisk) is a wild-card, useful for constructing catch-all routes, for example. Covered in *any* ASP.NET MVC tutorial. – bzlm Sep 25 '11 at 10:29

2 Answers2

13

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

Menol
  • 1,230
  • 21
  • 35
4

It is called catch all route mapping. See the below question as well :

Infinite URL Parameters for ASP.NET MVC Route

Community
  • 1
  • 1
tugberk
  • 57,477
  • 67
  • 243
  • 335