开发者

Best Practices with MVC Route

开发者 https://www.devze.com 2022-12-27 00:05 出处:网络
If this is asked before just point me in the right direction I am a OO and MVC newbie. I am following along the MVC Storefront(a little outdated now)

If this is asked before just point me in the right direction I am a OO and MVC newbie. I am following along the MVC Storefront(a little outdated now) where they are talking about routes and adding them to global.asax.cs

My question is this: wouldn't it be better if only 1 route is def开发者_运维知识库ined and after that everything is done programatically?

I don't want the user to navigate using the address bar.

thank you


First of all, if you define only one route in MVC, i.e. /{controller}/{action}/{id} (which is default btw.), the routing mechanism will work perfectly as every action in MVC must be defined in a controller.

Sometimes you may want to have some special routes, like /users/{id}/{username}, like this page has to create routes that make sense to your users and search engines. This is a very interesting approach very difficult to accomplish in ASP.NET (until 4.0).

IMHO there's nothing wrong having logical guessable route names in your application, it looks a lot better than having mysterious long urls with cryptic paths. Letting the user "guess" the urls is not bad at all.


Well,

ASP.NET MVC routing help's you to extend the URL SEO. At same time you will set a rule so that no human can directly access any resource via altering a url.

Thanks! Sandeep Sachan

0

精彩评论

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