如何为每个用户生成唯一的URL [英] how to generate unique url for each user

查看:89
本文介绍了如何为每个用户生成唯一的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为每个用户生成唯一的URL id

how to generate unique url id for each user

推荐答案

每个用户都将提供用于标识此人的唯一ID。如果某个ID正忙,系统会要求用户选择其他ID,直到选择新的唯一值。



一个问题是:此ID可能包含非法字符对于文件系统对象或URL的名称,因此您需要转义它们。其中一个最简单的方法是 UrlEncode

http://msdn.microsoft.com/en-us/library/zttxte6w%28v=vs.110%29.aspx [<一个href =http://msdn.microsoft.com/en-us/library/zttxte6w%28v=vs.110%29.aspxtarget =_ blanktitle =New Window> ^ ],

http://msdn.microsoft.com/ en-us / library / system.web.httputility.urlencode.aspx [ ^ ]。



UTL编码后,名称将保持唯一。但是,如果要使用其他一些转义方法,转义名称可能会变得非唯一。您需要在用户注册时选择URL的名称。如果您发现URL已被占用,请将其设为唯一,例如,通过向其附加一些整数。简单地从1开始,然后递增此值,直到得到的连接名称变为唯一(您可以开发具有更好性能的算法,这只是想法)。



-SA
Each user will provide a unique ID used to identify this person. If some ID is busy, the user will be asked to choose another ID, until a new unique value is chosen.

One problem is: this ID can contain characters illegal for the name of the file system object or URL, so you will need to escape them. One of the simplest ways to do it is UrlEncode:
http://msdn.microsoft.com/en-us/library/zttxte6w%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx[^].

After UTL encoding, the names will remain unique. However, if you want to use some other method of escaping, escaped names may become non-unique. You need to choose the name for the URL at the moment of user registration. If you find that the URL is already taken, make it unique, say, by appending some integer number to it. Simply start with, say, 1, and increment this value until the resulting concatenated name becomes unique (you can develop algorithm with better performance, this is just the idea).

—SA


这篇关于如何为每个用户生成唯一的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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