简体   繁体   English

如何自定义CreateUserWizard以获取UserId和UserName值?

[英]How to customize CreateUserWizard to get UserId and UserName values?

I am using Membership provider to deal with user registration and logging to the website. 我正在使用Membership provider来处理用户注册和登录网站。 This Membership provider is part of a package comes through: Membership provider程序是通过以下方式Membership provider的软件包的一部分:

Install-Package Microsoft.AspNet.Providers 安装包Microsoft.AspNet.Providers

I have two ASPX pages one has a CreateUserWizard control and the other has a Login control. 我有两个ASPX页面,一个具有CreateUserWizard控件,另一个具有Login控件。 The registration and logging is working correctly. 注册和日志记录工作正常。

I have defined Profile properties in the web.config file: 我在web.config文件中定义了Profile属性:

<profile defaultProvider="DefaultProfileProvider">
  <properties>
    <add name="Id" type="System.Guid" />
    <add name="UserName"/>
  </properties>

What I am trying to is to be able to take the UserId and UserName values on registration of the user, and store them to Profile.Id and Profile.UserName respectively. 我正在尝试的是能够在用户注册时获取UserIdUserName值,并将它们分别存储到Profile.IdProfile.UserName

How to customize the CreateUserWizard to achieve this?. 如何自定义CreateUserWizard以实现此目的?

My try: 我的尝试:
When you show CreateUserWizard on the browser. 在浏览器上显示CreateUserWizard时。 You can see a button named "Create User", so I thought it is a good place to extend on and add code to take the required values. 您会看到一个名为“创建用户”的按钮,因此我认为这是扩展并添加采用所需值的代码的好地方。 So I clicked the small arrow on CreateUserWizard and choose Customize Create User Setup , but the editable template doesn't include the corresponding button of "Create User". 因此,我单击了CreateUserWizard上的小箭头,然后选择“ Customize Create User Setup ,但是可编辑模板不包含“创建用户”的相应按钮。

So what is the possible way to achieve that? 那么,实现这一目标的可能方法是什么?

In the aspx file under events of the CreateUserWizard control, there is a "createdUser" event you can create. 在CreateUserWizard控件的事件下的aspx文件中,可以创建一个“ createdUser”事件。

In the cs file of the CreateUser function put in: 在CreateUser函数的cs文件中,输入:

    MembershipUser newUser = Membership.GetUser(NewUserWizard.UserName);
    Guid newUserId = (Guid)newUser.ProviderUserKey;

newUser.UserName will give you the UserName, and NewUserId will give you the id. newUser.UserName将为您提供UserName,NewUserId将为您提供ID。 At that point you should have what you need. 那时您应该拥有所需的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM