[英]What method of CreateUserWizard calls the Membership.CreateUser?
I made a Custom Membership Provider, with a custom CreateUser method that accepts one more argument, like this: 我做了一个自定义成员资格提供,与接受多一个参数,像这样的定制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
}
}
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... 问题在于,在调用此OnCreatingUser之后,控件会在内部调用提供程序的默认CreateUser方法(不执行任何操作),因为已插入用户而引发错误。
Its possible to prevent the second call, by overriding a method in the CustomCreateUser? 它可以防止第二个电话,通过覆盖在CustomCreateUser的方法?
Thanks in advance 提前致谢
This is sort of hacky, however you could do the following: 这有点hacky,但是您可以执行以下操作:
protected override void OnCreatingUser(LoginCancelEventArgs e)
{
MembershipUser newUser = ((CustomMembershipProvider)Membership.Provider).MyCreateUser(username,password,company, etc...)
e.Cancel = true;
}
Inside of the AttemptCreateUser code 在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...
This should override the default behavior of AttemptCreateUser since it will return false. 这将覆盖AttemptCreateUser的默认行为,因为它将返回false。 This was untested but i used a similar method when using the LoginControl with a custom security provider. 这未经测试,但与自定义安全提供程序一起使用LoginControl时,我使用了类似的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.