ASP.NET Roles and Profiles: best way to query for collection of users who match custom profile property?

戏子无情 提交于 2019-12-02 12:13:11

问题


ASP.NET 2.0 membership, roles, and profiles is the cat's meow. The API for roles supports handy methods like GetAllUsersInRole("MyNewsletterSubscriber"), which will return a collection of people in the "MyNewsletterSubscriber" role.

I am wondering what the best way to return a collection of people with custom ASP.NET Profile properties might be. So for example, I might create one custom profile property called IsNewsletter1SubscriptionUserSelectionTextOnly and another custom profile property called IsNewsletter1UserSelectionMobileOptimized.

How then, can I most efficiently query for something akin to GetAllUsersWithCustomProfileProperty("IsNewsletter1SubscriptionUserSelectionTextOnly", true);

For the use I'm envisioning, the API around Profiles seems underdeveloped -- I think Scott Guthrie mentioned some forthcoming work on it at his talk at Tech Ed 2006, but I don't know what's been done.

It may also be that I'm trying to use Profiles inappropriately, and it would be better to store all of this junk as straight roles. Don't know. I like the idea of using Roles or Profiles for list management, but I don't know the cleanest way to manage it.

Thoughts, idea, answers? Thanks...


回答1:


Well, querying on profiles--at least with the default SQL implementation--is scary because you are really querying on a binary serialized field, so every query needs to load every row in the database, deserialize said binary and then check the answer. So don't cheat and do it with LINQ to Objects or something, your DBA will shoot you.

Anyhow, my rule is as soon as you want to query on profile, you had better implement a custom provider that is queryable in a normal fashion. Usually this ends up being part of the domain model.



来源:https://stackoverflow.com/questions/1019725/asp-net-roles-and-profiles-best-way-to-query-for-collection-of-users-who-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!