简体   繁体   English

将用户数据与SID而不是用户名匹配?

[英]Matching User Data with SID instead of Username?

All the examples I can find for storing/filtering data in Lightswitch end up comparing usernames directly, for example: 我在Lightswitch中找到的用于存储/过滤数据的所有示例最终都直接比较了用户名,例如:

partial void OrdersForUser_PreprocessQuery(ref IQueryable query)
{
    // Only show the Orders for the current user
    query = query.Where(x => x.UserName == this.Application.User.Identity.Name);
}

This seems like a bad idea to me as usernames can (and do) change. 对我来说,这似乎是个坏主意,因为用户名可以(并且确实)可以更改。

Is the ASP.NET Membership UserID (a guid) or SID available somewhere to match on? ASP.NET成员身份用户ID(GUID)或SID是否可用于匹配?

To get the Membership UserID from the username, you can use: 要从用户名获取会员资格用户ID,可以使用:

MembershipUser CurrentUser = Membership.GetUser(this.Application.User.Identity.Name);
Guid userGuid = (Guid)CurrentUser.ProviderUserKey;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM