[英]ASP.NET Default Membership and Role Provider API
Suppose I have the following in my web.config: 假设我的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. 我希望此变量是
unique
,就像您将在sql server中指定unique
一样,这意味着所有成员用户可以有一个唯一的电话号码。
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? 是否可以使用ASP.NET 4.0为配置文件属性指定唯一属性? Thank you!
谢谢!
实现此目的最简单的方法-而不是试图将其插入Profile模型中-可能是创建一个由UserId索引的新表,其中Phone作为其自己的列,并具有唯一索引。
You cannot add properties to the default profile provider by adding xml elements to the config file. 您不能通过将xml元素添加到配置文件来将属性添加到默认配置文件提供程序。 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.
所有属性都已序列化并保存在单个BLOB列中 ,这意味着您不需要使它们中的任何一个,基于它们创建索引或直接在SQL中对它们进行查询。 I strongly encourage you to implement your own User & provider so that you have control over its persistence and behavior.
我强烈建议您实现自己的用户和提供程序,以便您对其持久性和行为进行控制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.