[英]User Identity in ASP.Net modelling
I have a table with Listings and I want users to be able to mark their favourite listings. 我有一个带有列表的表,希望用户能够标记自己喜欢的列表。 To do that I would have a new table with User ID and Listing Id data.
为此,我将创建一个包含用户ID和列表ID数据的新表。 Users should be only able to see their favourite listings.
用户应该只能看到自己喜欢的列表。
I am using ASP.NET default authentication. 我正在使用ASP.NET默认身份验证。 The way to get the User Id would be
获取用户ID的方法是
User.Identity.Name;
?? ??
Is that the userId I should store? 那是我应该存储的userId吗? Is that the common approach?
那是常用的方法吗?
The User.Identity.Name
will have the value of whatever you sign in the user with. User.Identity.Name
将具有您User.Identity.Name
登录用户的值。 For example with forms authentication: 例如,使用表单身份验证:
FormsAuthentication.SetAuthCookie(thisWillBeTheUserIdentityNameValue, false);
With claims authentication it will be the value you set for the claim type ClaimTypes.Name
: 使用声明身份验证时,它将是您为声明类型
ClaimTypes.Name
设置的值:
var claim = new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.Name, thisWillBeTheUserIdentityNameValue)
});
If you sign in the user with their user id you could use User.Identity.Name
. 如果使用用户ID登录用户,则可以使用
User.Identity.Name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.