开发者

How WebMatrix routing works?

开发者 https://www.devze.com 2023-02-06 19:58 出处:网络
With ASP MVC the routing works with the following code routes.MapRoute(\"Default\", \"{controller}/{action}/{id}\",

With ASP MVC the routing works with the following code

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

It is easy to change the contr开发者_Go百科ollers and actions. Do I have access to such a controller at WebMatrix? Or do i need to catch each variable with UrlData[0].ToString(). Thanks in advance!


I assume you are talking about routing in ASP.NET Web Pages, in which case there are no controllers. The default routing set-up treats URLs as file paths. If no matching file (ignoring the file extension) can be found on the first attempt to match, the last portion of the URL is treated as UrlData, and an attempt to match a file is made with the remainder of the URL, and so on and so on. More can be found here: WebMatrix - URLs, UrlData and Routing for SEO


Essentially, you get routing for free in ASP.NET Web Pages.

Routing for ASP.NET Web Pages is also explained on the asp.net web site, Customizing Site-Wide Behavior. See the very last section titled 'Creating More Readable and Searchable URLs'. This section describes the rules that are followed for routing and provides an example.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号