C# asp.net 自定义 MembershipUser.createUser() 方法,从 createuserwizard 控件调用它

发布于 2024-07-12 07:49:09 字数 778 浏览 7 评论 0原文

我创建了自定义 MembershipUser、MembershipProvider 和 RolePrivoder 类。 除了一件事之外,这些都有效,我对此非常满意。 我在“用户”表中有一个额外的字段。 我有一个重写的 CreateUser() 方法,它接受额外的变量并将其放入数据库中。

我的问题是我希望能够从“创建用户向导”控件中调用它。 我已经自定义了该控件,使其具有下拉菜单来填充我的额外字段。 我已使用以下代码来存储该信息,但我不知道如何使用配置文件或调用我的自定义 CreateUser 方法:

 // Create an empty Profile for the newly created user     
 ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);

 // Populate some Profile properties off of the create user wizard
 p.CurrentLevel = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue);

 // Save profile - must be done since we explicitly created it
 p.Save(); 

感谢您的所有帮助

Jon Hawkins

I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I am very happy with it, apart from one thing. I have an extra field in the "Users" table. I have an overridden method for CreateUser() that takes in the extra variable and puts it into the DB.

My issues is that I want to be able to have this called from the Create User Wizard control. I have customized the control to have a drop down to populate my extra field. I have used the following code to store that piece of info but I am at a loss of how I either use the profile or call my custom CreateUser Method:

 // Create an empty Profile for the newly created user     
 ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);

 // Populate some Profile properties off of the create user wizard
 p.CurrentLevel = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue);

 // Save profile - must be done since we explicitly created it
 p.Save(); 

Thank you for any and all help

Jon Hawkins

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

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

发布评论

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

评论(3

半暖夏伤 2024-07-19 07:49:09

我认为您的解决方案是您将获得的“最简单”的解决方案。 您可以创建自己的向导并调用正确的方法,但这需要更多的工作。

我唯一可以推荐的是使用 OnCreatedUser 事件代替。

参考:4guysfromrolla

I think your solution is the "easiest" you're going to get. You could create your own wizard and call the correct method, but that's a lot more work.

The only thing I could recommend is using the OnCreatedUser event instead.

reference: 4guysfromrolla

深海少女心 2024-07-19 07:49:09

这不是答案,但我找到了解决方法,仍然想知道是否有人可以直接回答这个问题...

public void UpdateCurrentLvl_OnDeactivate(object sender, EventArgs e)
{
    int level = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue);
    MyMembershipUser myUser = (MyMembershipUser)Membership.GetUser(CreateUserWizard1.UserName);
    myUser.CurrentLVL = level;
    Membership.UpdateUser(myUser);
}

在我的第一个 CreateUserWizardStep 中,如果将上面的方法放在停用时触发。 此时,它已将用户插入数据库,我可以取出用户,转换为我的 MembershipUser 类,设置变量和所有更新方法。

正如我所说,这是一种我希望解决的方法,但它确实有效。

谢谢

This is not the answer but I found a work around, would still like to know if someone could answer the question directly...

public void UpdateCurrentLvl_OnDeactivate(object sender, EventArgs e)
{
    int level = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue);
    MyMembershipUser myUser = (MyMembershipUser)Membership.GetUser(CreateUserWizard1.UserName);
    myUser.CurrentLVL = level;
    Membership.UpdateUser(myUser);
}

In my first CreateUserWizardStep if put the method above to fire on deactivate. As at this point it has inserted the user into the DB I can get the User out, cast to my MembershipUser class, set the variable and all the update method.

As I say this is a work around from the way I would liked to have solved it but it works.

Thanks

顾冷 2024-07-19 07:49:09

这也是令人难以置信的黑客行为,但在过去,当我不得不做类似的事情时,我只是将额外的值塞进未使用的参数中,例如密码重置问题或答案。 不过,我不完全确定您如何使用向导来管理它。

它很丑陋,但只要它被明确记录(为了安全起见,我会对该方法本身以及您引用它的任何地方进行评论),它就会正常工作。

与创建自己的向导相比,它的工作量也少得多。

This is also incredibly hacky, but in the past when I've had to do similar things, I've just crammed the extra value into an unused parameter, like the password reset question or answer. Though, I'm not entirely sure how you'd manage this using the wizard.

It's ugly, but as long as it is explicitly documented (to be safe, I'd comment on the method itself as well as anywhere you reference it) it will work fine.

It's also a lot less work than creating your own wizard.

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