Using Parts of GUID as ID

后端 未结 6 766
借酒劲吻你
借酒劲吻你 2021-01-18 21:40

I\'m developing an ASP .Net MVC application. One of my actions requires id as a parameter. For example:

public actionresult Detail(Guid id){
            


        
6条回答
  •  广开言路
    2021-01-18 22:39

    Bit of a late response but in case anyone reads this...

    depending on the use, you can provided a shortened GUID value.

    for instance, if the ID value is generated and given to the user as an Authentication Token sort of value then during the generation you could just take however many characters and compare it with other in use values. if any matches, then just generate a new one and re-compare until its unique.

    This technique is also advisable if you trim a hash value of the GUID too.. just to be safe. In fact any time you randomly generate a value to be used as ID then you should make sure it is not 'already in use'

提交回复
热议问题