问题描述
我不断听到,我不应该在我的asp.net mvc的URL中使用主键来
i keep hearing that i shouldn't be using primary keys in my asp.net mvc url
例如:/用户/编辑/ 1243
for example: /Users/Edit/1243
什么是这里的问题?
什么是另类,投入的用户名?因为你希望它是独一无二的,它看起来像主键是最清洁的选择。
what is the alternative, putting in user names? as you want it to be unique, it seems like primary key is the cleanest option
想法?
推荐答案
我看不出把主键对URL的问题(既做堆栈溢出和无数其他网站无论是对此事的创造者)。这是经常做的一件事是供应的主键,并提供一个搜索引擎和用户友好的即数据的人类可读的标题,所述标识符链接。
I don't see any problem with putting the primary key on the URL (neither do the creators of Stack Overflow and countless other sites either for that matter). One thing that is often done is to supply the primary key and also supply a SEO and user friendly "slug" that is a human-readable title of the data that the identifier links to.
如果您打算的确定的资源(在你的情况下,用户账号),你将不得不在URL供应的唯一标识符的。即使你决定不使用主键仍然必须选择一个无法改变的标识符。
If you intend to identify a resource (in your case, a user account) you will have to supply a unique identifier on the URL. Even if you decide to not use the primary key you must still choose an identifier that cannot change.
这篇关于使用主键在asp.net mvc的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!