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. Users should be only able to see their favourite listings.
I am using ASP.NET default authentication. The way to get the User Id would be
User.Identity.Name;
??
Is that the userId I should store? Is that the common approach?
The User.Identity.Name
will have the value of whatever you sign in the user with. 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
:
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.