开发者

Overriding SQLMembershipProvider

Is there built in methods into .net framework to do the following:

  1. Get role GUID from user name/user GUID
  2. Get role name from role GUID

So far I have been sending queries to the asp_roles and asp_users tables to obtain that information and I'm wondering if there is a nicer way of doing this?

I have the following methods that I store in the ASPUtilities class:

getRoleGUID(guid userGuid) { LINQ joins }

getRoleGuid(string userName) { LINQ joins  }

getRoleName(guid roleGuid) { LINQ joins  }

EDIT:

I hav开发者_高级运维e just looked into extending SQLMembershipProvider examples.

Few examples completely override the SQLMembershipProvider, but I think what I'm interested is just adding few extra methods to deal with the roles by using LINQ. Is this feasible?


If you extend the SQLMembership provider, it will do the exact same thing, send queries to the database to get that information since the roleID is not stored in session. If you don't want to go through that much trouble, you could do a few things.

  1. Create a custom class with these methods that you can call and will return the ID for you of your role. Essentially, move all of your queries to one location.
  2. Store the role ID in session on login. Call your method you created above once and don't requery everytime. Not 100% of the security risks with this one, however, since you are storing some possibly sensitive role information, the id, in session. Might just be overly cautious though :)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜