Question

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!

Was it helpful?

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.

OTHER TIPS

You cannot add properties to the default profile provider by adding xml elements to the config file. You need to implement a customer Membership User type with the properties that you need.

edit

The generated Membership User based on the config you create is not backed by a database schema you can work with. All of the properties are serialized and stashed in a single BLOB column, which means you can't make any of them required, create an index based on them, or query directly against them in SQL. I strongly encourage you to implement your own User & provider so that you have control over its persistence and behavior.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top