ASP.NET SqlMembershipProvider:唯一但不是必需的电子邮件?

发布于 2024-09-27 01:10:22 字数 201 浏览 7 评论 0原文

有没有办法配置 ASP.NET SqlMembershipProvider,使电子邮件是可选的,但提供时必须是唯一的?

我只找到了 requiredUniqueEmail 属性 (web.config),它使电子邮件成为强制性的。我是否必须在帐户注册过程中忽略这一点并自行检查现有电子邮件地址?

或者有更好的方法来处理这种情况吗?

Is there a way to configure ASP.NET SqlMembershipProvider such that Email is optional but when provided must be unique?

I only found the requiredUniqueEmail attribute (web.config) which makes Email mandatory. Do I have to leave this out and implement checking for existing email addresses myself in the account registration process?

Or is there a nicer way to handle this scenario?

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

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

发布评论

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

评论(1

三生路 2024-10-04 01:10:22

一种简单但可能有风险的方法是直接修改存储过程来执行此操作。

修改 aspnet_Membership_CreateUser ,将: 替换为:

IF (@UniqueEmail = 1)
BEGIN
    IF (EXISTS (SELECT *
                FROM  dbo.aspnet_Membership m WITH ( UPDLOCK, HOLDLOCK )
                WHERE ApplicationId = @ApplicationId AND LoweredEmail = LOWER(@Email)))
    BEGIN
        SET @ErrorCode = 7
        GOTO Cleanup
    END
END

    IF (EXISTS (SELECT *
                FROM  dbo.aspnet_Membership m WITH ( UPDLOCK, HOLDLOCK )
                WHERE ApplicationId = @ApplicationId AND LoweredEmail = LOWER(@Email)))
    BEGIN
        SET @ErrorCode = 7
        GOTO Cleanup
    END

说这是有风险的,因为没有人会期望您修改此内容,并且您最好很好地记录更改。

An easy, but probably risky way, is to modify the stored procedure directly to do this.

Modify aspnet_Membership_CreateUser by replacing:

IF (@UniqueEmail = 1)
BEGIN
    IF (EXISTS (SELECT *
                FROM  dbo.aspnet_Membership m WITH ( UPDLOCK, HOLDLOCK )
                WHERE ApplicationId = @ApplicationId AND LoweredEmail = LOWER(@Email)))
    BEGIN
        SET @ErrorCode = 7
        GOTO Cleanup
    END
END

with

    IF (EXISTS (SELECT *
                FROM  dbo.aspnet_Membership m WITH ( UPDLOCK, HOLDLOCK )
                WHERE ApplicationId = @ApplicationId AND LoweredEmail = LOWER(@Email)))
    BEGIN
        SET @ErrorCode = 7
        GOTO Cleanup
    END

I say it's risky because nobody would expect you to modify this and you'd better document the change well.

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