-
Intro
-
Inbound Routing
- URL
- Routing System
- RouteData
- handled by MVC
-
Outbound Routing
- Helper
- RouteData
- search the config
- construct the URL
-
Demo
- when no Home controller
root URL throws YSOD
- change default route config to Jobs
- Html.ActionLink
- add a Details Action
- clean up the URL
- new Routing entry routes.MapRoute()
-
order of entries is respected
- put the most specific entries first
- may need a constraint (id should be digits only)
- to avoid conflicts with existing route configs
-
Routes.MapRoute
- route name
- URL pattern
-
defaults
- means that segments can then be optional
-
constraints
- must be satisfied
-
Outbound
- default-only treated as extra constraints
- extra params are appended to query string
-
further features
-
physical files on disk
- don't match the routing entries
- allows IIS to just serve the file
- RouteExistingFiles property
-
Routes.IgnoreRoute
- to selectively white-list files to allow to be served
-
catch-all params using *
- entire string after * matched
so need to be the last segment in the URL
-
named route entries
- helps with Outbound routing
- Html.RouteLink
- no guarantee they'll match incoming route
- prob. best to not use them
-
custom route handlers
- e.g.
- IRouteHandler
- GetHttpHandler
- not reusable
- ProcessRequest
- routes.Add(new Route())
- parameters can be passed into the request processing
- prob. not all that useful
-
SEO
- add an extension to a Model class
to easily pull out potentially useful route params
- build a RouteValueDictionary
- import the namespace into a View
- Html.RouteLink
- generate URL from arbitrary list of route params
- update the routing config so that they really are params
not just appended to querystring
- maybe no longer need the id any longer
-
normalise the URL
- change null -> empty string
- replace whitespace (dashes)
- remove unusual characters
- this is OK if we still only rely on the id parameter
-
non-canonicalisation problem
- only have a single URL mapping to a resource
- enforce canonical URLs
-
add code to controller to compare
- Request.Url.PathAndQuery
- Url.RouteUrl(routeValueDictionary)
- redirect - do HTTP:301 (permanently moved)
-
Areas
- a way of orgnaising the app
-
have their own
- Controllers
- Views
- content files
- Routing config
-
create area
- creates folder structure
- how does it work
didn't add anything to Route config
- Application_Start
- new class inheriting from AreaRegistration
-
RegisterArea
- Area registers it's own Routes
-
problems?
-
controllers with the same name
- conflicts at top-level
- equal priority to all namespaces
- need provide the namespace in the global Route config