ASP.NET路由问题 [英] ASP.NET Routing Question

查看:136
本文介绍了ASP.NET路由问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么是这样的:

  http://MySite.com/Project/24/Search/32/Edit/49

preferred在这个?

  http://MySite.com/Project/24?Search=32&Edit=49


解决方案

我不知道你在哪里premise是从哪里来的?它看起来像一个人为的例子,这使得它很难评论。

有一个更好的比较会是这样的:

  http://MySite.com/Project/24/Members/Edit

相对于

  http://MySite.com/Projects.aspx?id=24&section=Members&action=Edit

其中,除其他事项外,实体的层次是从第一个例子(即一个项目包含的成员)显而易见。这也表明,你可以使用包含类似结构的第一个(即 /项目/ 24 /项目/ 24 /成员其他网址),所以在这个意义上它是更简洁。

如果它归结为具有可变数量的参数,如搜索行动,那么它是完全正常使用URL参数,因为这会给你更多的灵活性,例如:

  http://MySite.com/Projects/Search?name=KillerApp&type=NET

您可以构建使用的第一个样式URL,但是你没有真正得到什么,以及管理路由可能增加不必要的开销:

  http://MySite.com/Projects/Search/name/KillerApp/type/NET

我认为这(或任何类似的建筑,例如,如果你删除了参数名称)患有一种人造的层次结构 - 在这种情况下,动作真的搜索,以及其他一切仅仅是一个搜索参数,所以它的在同一层级,而不是一些亚健康的层次结构。

Why is this:

http://MySite.com/Project/24/Search/32/Edit/49

preferred over this?

http://MySite.com/Project/24?Search=32&Edit=49

解决方案

I'm not sure where your premise is coming from? It looks like an artificial example, which makes it hard to comment on.

A better comparison would be something like:

http://MySite.com/Project/24/Members/Edit

As opposed to:

http://MySite.com/Projects.aspx?id=24&section=Members&action=Edit

Where, among other things, the hierarchy of entities is immediately obvious from the first example (ie, a Project contains Members). It also suggests that you can use other URLs that contain similar structures to the first (ie, /Projects/24 and /Projects/24/Members), so in that sense it's more concise.

If it comes down to actions that have a variable number of parameters, such as searching, then it's totally fine to use URL parameters as this will give you more flexibility, eg:

http://MySite.com/Projects/Search?name=KillerApp&type=NET

You could construct a URL using the first style, but you don't really gain anything, and managing the route could add unnecessary overhead:

http://MySite.com/Projects/Search/name/KillerApp/type/NET

I would argue that this (or any similar construction, eg if you removed the param names) suffers from an artificial hierarchy - the action in this case is really Search, and everything else is just a parameter of the Search, so it's in the same hierarchy, not some "sub" hierarchy.

这篇关于ASP.NET路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆