Link to home
Start Free TrialLog in
Avatar of killdurst
killdurst

asked on

Visual Studio Express 2013 for Web: Registering a new account using email instead of username

Hi, I created a new asp.net web forms site in Visual Studio Express 2013 for Web, and the default Register account page created by the software is asking the user to enter a username, password and confirm password.

How do I edit this form to ask the user to enter email instead of username?

I want the "email" textfield to be both required and validated as email, so I added a "RegularExpressionValidator" below the "RequiredFieldValidator" as follows...

<asp:TextBox runat="server" ID="UserName" CssClass="form-control" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="UserName" CssClass="text-danger" ErrorMessage="The email field is required." />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="UserName" CssClass="text-danger" ErrorMessage="Please enter a valid email." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />

Open in new window


Is this the correct way? Because the "Please enter a valid email." error message is  appearing a bit too the right, as in the attached screenshot "email.jpg".

Second question, still on the register account page, even after entering a valid looking email, the two password fields and pressing "Register", there is an error message that says "User name 2@2.com is invalid, can only contain letters or digits".

In "Register.aspx.vb", there is the following code...

Public Partial Class Account_Register
    Inherits Page
    Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
        Dim manager = New UserManager()
        Dim user = New ApplicationUser() With {.UserName = userName.Text}
        Dim result = manager.Create(user, Password.Text)
        If result.Succeeded Then
            IdentityHelper.SignIn(manager, user, isPersistent:=False)
            IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
        Else
            ErrorMessage.Text = result.Errors.FirstOrDefault()
        End If
    End Sub
End Class

Open in new window


The "manager.Create" function is under "UserManagerExtensions" under "Microsoft.AspNet.Identity.Core" under "Object Browser".

What do I need to do so that I can register a new account using email address successfully?
Thanks.
email.jpg
SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of killdurst
killdurst

ASKER

Cool, thanks!
Ok, now hoping for an answer to the second question... :)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Seems that with backbone, we have to use "project" and "C#" instead of "web site" and "visual basic". And I encountered an error when creating a new backbone project. See attached screenshot.

Anyway, as an alternative, can the "Register" page be updated to include an "email" field?
What are the files that needs to be updated so the the email field is also stored in the database?

Basically, I would like to create an asp.net site using visual basic that would also allow users to also reset password and stuff. If there are any free templates or easy to use cms/frameworks out there, do let me know. Thanks.
error.jpg
Just thought of a workaround for this...

I am thinking of converting the email that the user inputs on the register page into a hash string or just numbers just so that the account can be registered.
But the converted string must only have letters and digits, no "+", "/", "=", etc.

Of course, the hashed string must be able to be restored as the email address so that I can display it on the header and stuff.

What are the ways I can convert the email into a string made up of just letters and digits?