How does WebMatrix routing work?

With ASP MVC, routing works with the following code

routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });

Easy to change controllers and actions. Do I have access to this controller in WebMatrix? Or I need to catch every variable with UrlData[0].ToString() . Thanks in advance!

+4
source share
3 answers

I assume that you are talking about routing in ASP.NET web pages, in which case there are no controllers. The default routing setting treats URLs as file paths. If the first attempt does not find a matching file (ignoring the file extension), the last part of the URL is treated as UrlData, and an attempt is made to map the file to the rest of the URL, etc. and so on. More details can be found here: WebMatrix - URL, UrlData and Routing for SEO

+3
source

Essentially, you get free routing in ASP.NET web pages.

The routing for ASP.NET web pages is also explained on asp.net, "Configuring Site Behavior." See the last section, β€œCreating More Readable and Searchable URLs.” This section describes the rules that apply to routing and provides examples.

+3
source

Here is another page that describes how routing works with WebMatrix http://www.asp.net/webmatrix/tutorials/18-customizing-site-wide-behavior

+1
source

Source: https://habr.com/ru/post/1336691/


All Articles