17
ASP.NET MVC ROUTE Jason

Mvc route

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Mvc route

ASP.NET MVC ROUTEJason

Page 2: Mvc route

URL Routing

Page 3: Mvc route

URLsURL Action

http://example.com/Users/Edit/5 UsersController.Edit(5)

http://example.com/Users/Edit UsersController.Edit()

http://example.com/Users UsersController.Index()

http://example.com HomeController.Index()

Page 4: Mvc route

Register Routes RouteConfig.cs

Global.asax.cs

Page 5: Mvc route

Catch-all Example

/example.axd/d1/d2/d3/d4

{resource}.axd/{pathInfo} /example.axd/d1

{resource}.axd/{*pathInfo} /example.axd/d1/d2/d3/d4

Page 6: Mvc route

Static Routs Example

http://example.com/privacy

Page 7: Mvc route

Dynamic Routs Example

http://example.com/products/10/buy

Page 8: Mvc route

Route Constraints - Regex Example

http://example.com/basket http://example.com/checkout

Page 9: Mvc route

Route Constraints - Regex Example

http://example.com/Product/3

Page 10: Mvc route

Route Constraints - IRouteConstraint Example

http://example.com/Admin/Log

Page 11: Mvc route

Route Constraints - IRouteConstraint Custom Route Constraint

Page 12: Mvc route

Route Namespace Parameters

Page 13: Mvc route

Routes Collection The order in which you added them to the Routes collection

 http://server/application/products/show/bikes

Route 1 is set to {controller}/{action}/{id}

Route 2 is set to products/show/{id}

Page 14: Mvc route

Route Error Handle NotFoundResult.cs

ErrorController.cs

Page 15: Mvc route

Route Error Handle

Page 16: Mvc route

Q&A