I’m doing my first project based on ASP.NET Membership and I’m having issues with figuring out how to relate my custom data to a specific member. What is the convention here?
For example I’m wanting to make a web app where people can vote on different things. To ensure that people don’t vote over and over again I’m wanting to track who has voted on what poll. (I’m providing an example of my intended use, but am mainly interested in a generic implementation)
Does anyone know of already written guides online or other good resources for this?
IF** it’s relevant, I’m using EF4 for my db access (I don’t directly need assistance with EF and/or db access only how the membership is related to other data). At the moment I’m planning on having the membership stored in MsSQL and the rest of the data in MySQL due to the space that GoDaddy gives me on each database.
You need to uniquely identify the currently logged in user. It’s most likely you’ll want to use
MembershipUser.ProviderUserKey, which is the unique identifier provided by the particular flavor ofMembershipProvider. In the case ofSqlMembershipProvider, the value of this property is aGuid.So you can have a property on your vote record, like this (assuming you are using the
SqlMembershipProvider):You can get the current user’s ID like this:
Of course, from here you can query to make sure no
VoteswithUserId == userIdexist before you create and save a new vote.