Search code examples
c#asp.net.netasp.net-membershipasp.net-profiles

ASP.NET Default Membership and Role Provider API


Suppose I have the following in my web.config:

<profile enabled="true">
<providers>
...
<add name="Phone" type="System.String" defaultValue="" />

I would like this variable to be unique just like you would specify a unique in sql server or whatever, meaning there can be one unique phone number for all membership users.

Is this possible? I've been searching for a while for a fix but the only solution I can find is to create a new table just for storing unique numbers.

Is there a way to specify a unique attribute to a profile property using ASP.NET 4.0? Thank you!


Solution

  • The easiest way to do this -- rather than trying to shoe-horn it into the Profile model -- is probably to create a new table indexed by UserId, with Phone as a column of its own, with a unique index.