CreateUserWizard 的什么方法调用Membership.CreateUser?

发布于 2024-08-08 09:44:55 字数 1226 浏览 3 评论 0原文

我创建了一个自定义成员资格提供程序,其中包含一个自定义 CreateUser 方法,该方法接受另一个参数,如下所示:

public class CustomMembershipProvider : MembershipProvider
        {
            // code

            public override MembershipUser CreateUser(string username,
                                                       string password, etc...)
            {
                  // does nothing
            }

            public MembershipUser MyCreateUser(string username,string password,string COMPANY, etc...)
            {
                  // validades the fields and inserts the user in the db
            }
        }

现在我想使用“创建用户向导”控件通过该额外字段插入用户。 我已将控件扩展为如下所示:

     public class CustomCreateUser : CreateUserWizard
        {
            public CustomCreateUser(): base()
            {
            }

            protected override void OnCreatingUser(LoginCancelEventArgs e)
            {
                  MembershipUser newUser = ((CustomMembershipProvider)Membership.Provider).MyCreateUser(username,password,company, etc...)
            }
    }

问题是,在调用此 OnCreatingUser 后,控件在内部调用提供程序的默认 CreateUser (不执行任何操作的方法),抛出错误,因为用户已插入

......是否可以通过重写 CustomCreateUser 中的方法来防止第二次调用?

提前致谢

I made a Custom Membership Provider, with a custom CreateUser method that accepts one more argument, like this:

public class CustomMembershipProvider : MembershipProvider
        {
            // code

            public override MembershipUser CreateUser(string username,
                                                       string password, etc...)
            {
                  // does nothing
            }

            public MembershipUser MyCreateUser(string username,string password,string COMPANY, etc...)
            {
                  // validades the fields and inserts the user in the db
            }
        }

And now i want to use the Create User Wizard control to insert users, with that extra field.
I have extended the control to something like this:

     public class CustomCreateUser : CreateUserWizard
        {
            public CustomCreateUser(): base()
            {
            }

            protected override void OnCreatingUser(LoginCancelEventArgs e)
            {
                  MembershipUser newUser = ((CustomMembershipProvider)Membership.Provider).MyCreateUser(username,password,company, etc...)
            }
    }

The problem is that after this OnCreatingUser is called, the control calls the provider's default CreateUser (the one that does nothing) method internally, throwing an error because the user was already inserted...

Its possible to prevent the second call, by overriding a method in the CustomCreateUser?

Thanks in advance

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

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

发布评论

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

评论(1

蹲墙角沉默 2024-08-15 09:44:55

这有点 hacky,但是您可以执行以下操作:

            protected override void OnCreatingUser(LoginCancelEventArgs e)
            {
                  MembershipUser newUser = ((CustomMembershipProvider)Membership.Provider).MyCreateUser(username,password,company, etc...)

e.Cancel = true;
            }

在 AttemptCreateUser 代码内部

private bool AttemptCreateUser()
{
    if ((this.Page == null) || this.Page.IsValid)
    {
        MembershipCreateStatus status;
        LoginCancelEventArgs e = new LoginCancelEventArgs();
        this.OnCreatingUser(e);
        if (e.Cancel)
        {
            return false;
        }
....More code...

这应该覆盖 AttemptCreateUser 的默认行为,因为它将返回 false。
这未经测试,但我在将 LoginControl 与自定义安全提供程序一起使用时使用了类似的方法。

This is sort of hacky, however you could do the following:

            protected override void OnCreatingUser(LoginCancelEventArgs e)
            {
                  MembershipUser newUser = ((CustomMembershipProvider)Membership.Provider).MyCreateUser(username,password,company, etc...)

e.Cancel = true;
            }

Inside of the AttemptCreateUser code

private bool AttemptCreateUser()
{
    if ((this.Page == null) || this.Page.IsValid)
    {
        MembershipCreateStatus status;
        LoginCancelEventArgs e = new LoginCancelEventArgs();
        this.OnCreatingUser(e);
        if (e.Cancel)
        {
            return false;
        }
....More code...

This should override the default behavior of AttemptCreateUser since it will return false.
This was untested but i used a similar method when using the LoginControl with a custom security provider.

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