CreateUserWizard 的什么方法调用Membership.CreateUser?
我创建了一个自定义成员资格提供程序,其中包含一个自定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有点 hacky,但是您可以执行以下操作:
在 AttemptCreateUser 代码内部
这应该覆盖 AttemptCreateUser 的默认行为,因为它将返回 false。
这未经测试,但我在将 LoginControl 与自定义安全提供程序一起使用时使用了类似的方法。
This is sort of hacky, however you could do the following:
Inside of the AttemptCreateUser 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.