使用GUID的部分为ID [英] Using Parts of GUID as ID
问题描述
我开发一个ASP.NET的MVC应用程序。我的一个行为都需要 ID
作为参数。例如:
I'm developing an ASP .Net MVC application. One of my actions requires id
as a parameter. For example:
public actionresult Detail(Guid id){
return View();
}
正如你所看到的,我使用的的Guid
而不是内部
。问题是更多的化妆品。该URL可以是很长的,如本地主机/详细信息/ 0c157b42-379d-41d5-b9ba-83e9df9985b2
。
As you can see, I'm using Guid
instead of Int
. The issue is more cosmetic. The url can be very long, such as localhost/Detail/0c157b42-379d-41d5-b9ba-83e9df9985b2
.
它是安全的需要只有部分的的Guid
如本地主机/详细信息/ 0c157b42
?
Is it safe to take only parts of the Guid
like localhost/Detail/0c157b42
?
推荐答案
的GUID被设计以这样一种方式,它旨在是唯一的,但它的任何部分不是。请参见这个博客帖子了解详情。如果您需要缩短GUID利用它好的哈希 - 就像SHA-1(如果你没有安全问题)MD5
GUID is designed in such a way that it is intended to be unique, but any part of it is not. See this blog post for details. If you need to shorten the GUID take a good hash of it - like SHA-1 or (if you don't have security concerns) MD5.
这篇关于使用GUID的部分为ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!