ASP.NET 默认成员身份和角色提供程序 API

发布于 2025-01-07 03:57:33 字数 354 浏览 1 评论 0原文

假设我的 web.config 中有以下内容:

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

我希望这个变量是唯一的,就像您在 sql server 或其他什么中指定唯一的一样,这意味着所有会员都可以有一个唯一的电话号码用户。

这可能吗?我一直在寻找解决方案一段时间,但我能找到的唯一解决方案是创建一个新表仅用于存储唯一数字。

有没有办法使用 ASP.NET 4.0 为配置文件属性指定唯一属性? 谢谢你!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋叶绚丽 2025-01-14 03:57:33

要做到这一点,最简单的方法(而不是试图将其硬塞到 Profile 模型中)可能是创建一个由 UserId 索引的新表,其中 Phone 作为其自己的列,并具有唯一索引。

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.

不乱于心 2025-01-14 03:57:33

您无法通过将 xml 元素添加到配置文件来向默认配置文件提供程序添加属性。您需要使用您输入的属性实现客户会员用户类型需要。

编辑

基于您创建的配置生成的会员用户不受您可以使用的数据库架构的支持。所有属性都被序列化并存储在 单个 BLOB 列,这意味着您不能将它们中的任何一个作为必需项、基于它们创建索引或直接在 SQL 中查询它们。我强烈鼓励您实现自己的用户和应用程序。提供者,以便您可以控制其持久性和行为。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文