在ASP.NET LogIn Control中使用电子邮件作为用户名

时间:2022-06-29 08:25:37

I want to use the regular login system in an ASP.NET app, but I want to use the user's email address as their user name (as is common in many web sites.) However, there seems to be no property or attribute to allow me to do something like this; user name and email address always seem to be separate. Is it possible to do this or is some complex customization required? Thanks.

我想在ASP.NET应用程序中使用常规登录系统,但我想使用用户的电子邮件地址作为其用户名(在许多网站中很常见。)但是,似乎没有允许的属性或属性我做这样的事;用户名和电子邮件地址似乎总是分开的。可以这样做还是需要一些复杂的定制?谢谢。

3 个解决方案

#1


7  

I'm assuming you're talking about the CreateUserWizard control.

我假设你在谈论CreateUserWizard控件。

In the designer, right click on the CreateUserWizard control and select "Customize Create User Step". This will allow you to delete the email field row. I'd also recommend adding a RegularExpressionValidator to validate the email format for the user name.

在设计器中,右键单击CreateUserWizard控件并选择“自定义创建用户步骤”。这将允许您删除电子邮件字段行。我还建议添加RegularExpressionValidator来验证用户名的电子邮件格式。

To copy the user name to the email address, handle the CreatingUser event and do it there:

要将用户名复制到电子邮件地址,请处理CreatingUser事件并在那里执行:

protected void CreateUserWizard1_CreatingUser( object sender, LoginCancelEventArgs e )
{
    CreateUserWizard1.Email = CreateUserWizard1.UserName;
}

#2


6  

Having done this same thing for multiple web sites, it ended up being easiest to just use the email address for the UserName and the EmailAddress fields, rather than trying to change the Membership API to use the existing EmailAddress field over UserName.

为多个网站完成同样的事情后,最简单的方法就是使用UserName和EmailAddress字段的电子邮件地址,而不是尝试更改Membership API以使用UserName上的现有EmailAddress字段。

#3


1  

You have write your custom membership provider for that. For that you have inherit the membership provider class and need to create your own membership provider.

您已为此编写自定义成员资格提供程序。为此,您已继承成员资格提供程序类,并需要创建自己的成员资格提供程序。

Here are some good links for you..

这里有一些很好的链接..

http://www.15seconds.com/issue/050216.htm

Here is link for good discussions.

这是良好讨论的链接。

http://forums.asp.net/t/1146571.aspx

#1


7  

I'm assuming you're talking about the CreateUserWizard control.

我假设你在谈论CreateUserWizard控件。

In the designer, right click on the CreateUserWizard control and select "Customize Create User Step". This will allow you to delete the email field row. I'd also recommend adding a RegularExpressionValidator to validate the email format for the user name.

在设计器中,右键单击CreateUserWizard控件并选择“自定义创建用户步骤”。这将允许您删除电子邮件字段行。我还建议添加RegularExpressionValidator来验证用户名的电子邮件格式。

To copy the user name to the email address, handle the CreatingUser event and do it there:

要将用户名复制到电子邮件地址,请处理CreatingUser事件并在那里执行:

protected void CreateUserWizard1_CreatingUser( object sender, LoginCancelEventArgs e )
{
    CreateUserWizard1.Email = CreateUserWizard1.UserName;
}

#2


6  

Having done this same thing for multiple web sites, it ended up being easiest to just use the email address for the UserName and the EmailAddress fields, rather than trying to change the Membership API to use the existing EmailAddress field over UserName.

为多个网站完成同样的事情后,最简单的方法就是使用UserName和EmailAddress字段的电子邮件地址,而不是尝试更改Membership API以使用UserName上的现有EmailAddress字段。

#3


1  

You have write your custom membership provider for that. For that you have inherit the membership provider class and need to create your own membership provider.

您已为此编写自定义成员资格提供程序。为此,您已继承成员资格提供程序类,并需要创建自己的成员资格提供程序。

Here are some good links for you..

这里有一些很好的链接..

http://www.15seconds.com/issue/050216.htm

Here is link for good discussions.

这是良好讨论的链接。

http://forums.asp.net/t/1146571.aspx