ASP.Net建模中的用户身份

时间:2015-07-27 17:31:38

标签: asp.net sql-server database asp.net-web-api user-identification

我有一个包含商家信息的表格,我希望用户能够标记自己喜欢的商家信息。为此,我将有一个包含User ID和Listing Id数据的新表。用户应该只能看到自己喜欢的列表。

我正在使用ASP.NET默认身份验证。获取用户ID的方法是

User.Identity.Name;

...

那是我应该存储的userId吗?这是常用方法吗?

1 个答案:

答案 0 :(得分:0)

.responsive { width: 100%; display: block; text-align: center; } 将具有您在用户中签名的任何值。例如,使用表单身份验证:

User.Identity.Name

使用声明身份验证,它将是您为声明类型FormsAuthentication.SetAuthCookie(thisWillBeTheUserIdentityNameValue, false); 设置的值:

ClaimTypes.Name

如果您使用用户ID登录用户,则可以使用var claim = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, thisWillBeTheUserIdentityNameValue) });