Regarding ASP.NET routing in WebForm & Asterisk sign
Asked Answered
R

2

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.

Rom answered 25/9, 2011 at 10:8 Comment(1)
"Astrix"? Is this via google translate? :) The star is a wild-card, useful for constructing catch-all routes, for example. Covered in any ASP.NET MVC tutorial.Blackout
A
4

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

Infinite URL Parameters for ASP.NET MVC Route

Arabinose answered 25/9, 2011 at 21:27 Comment(0)
A
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

Aquamanile answered 26/7, 2016 at 14:19 Comment(1)
this answer is clearer and easier to understand than the accepted one!Wyatan
A
4

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

Infinite URL Parameters for ASP.NET MVC Route

Arabinose answered 25/9, 2011 at 21:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.