我应该使用的用户名或用户ID来引用ASP.NET身份验证的用户 [英] Should I use the username, or the user's ID to reference authenticated users in ASP.NET
本文介绍了我应该使用的用户名或用户ID来引用ASP.NET身份验证的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,在我简单的学习网站,我使用内置的ASP.NET身份验证系统。
So in my simple learning website, I use the built in ASP.NET authentication system.
我现在增加一个用户表保存的东西像他的拉链,出生日期等。我的问题是:
I am adding now a user table to save stuff like his zip, DOB etc. My question is:
- 在新表中,应重点是用户名(字符串)或它是GUID期待他们在
使用asp_表数量的用户ID
。 - 如果最好的做法是使用GUID丑,没有人知道如何得到它?它似乎无法访问一样容易名称(
System.Web.HttpContext.Current.User.Identity.Name
) - 如果您建议我既不使用(而不是GUID也不由ASP.NET验证提供的用户名字段),然后我怎么做它用ASP.NET验证?一种选择我喜欢的是使用用户作为登录的电子邮件地址,但我如何使ASP.NET身份验证系统中使用的电子邮件地址而不是用户的名字? (或者有什么在那里做,那只是我的决定我知道的userName实际上是一个电子邮件地址?
请注意:
- 我不问如何在.NET中得到一个GUID,我只是指在
asp_表
的GUID。 的用户ID列 - 的用户名是ASP.NET验证独一无二的。
- I am not asking on how get a GUID in .NET, I am just referring to the userID column in the
asp_ tables
as guid. - The user name is unique in ASP.NET authentication.
推荐答案
我会建议使用用户名作为表的主键如果用户名将会是唯一的,有几个很好的理由这样做:
I would suggest using the username as the primary key in the table if the username is going to be unique, there are a few good reasons to do this:
- \r
- 的主键将是一个聚集索引,因此搜索通过他们的用户名的用户的详细信息会非常快。 \r
- 它将停止重复的用户名出现 \r
- 您不必担心使用的信息的两种不同的peices(用户名或GUID) \r
- 这将使写作code多,因为不必查找两位信息更容易。 \r
- The primary key will be a clustered index and thus search for a users details via their username will be very quick.
- It will stop duplicate usernames from appearing
- You don't have to worry about using two different peices of information (username or guid)
- It will make writing code much easier because of not having to lookup two bits of information.
这篇关于我应该使用的用户名或用户ID来引用ASP.NET身份验证的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文