Solved

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

Posted on 2013-12-02
5
1,855 Views
Last Modified: 2014-01-13
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
0
Comment
Question by:killdurst
  • 3
  • 2
5 Comments
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 500 total points
ID: 39691656
For the first question you just need to set the display property for both validators to be dynamic, then it won't reserve the space for the validators unless it is needed (i.e when an error occurs) :

<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."  Display="Dynamic"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="UserName" CssClass="text-danger" ErrorMessage="Please enter a valid email." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic"/>

Open in new window

0
 
LVL 1

Author Comment

by:killdurst
ID: 39691690
Cool, thanks!
Ok, now hoping for an answer to the second question... :)
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 39691696
Seems that allowing users to register with emails is not supported out of the box with ASP.Net Identity but there is a community template that allows it to be done see:

http://www.asp.net/single-page-application/overview/templates/backbonejs-template
0
 
LVL 1

Author Comment

by:killdurst
ID: 39691742
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
0
 
LVL 1

Author Comment

by:killdurst
ID: 39692052
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?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now