Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-02
5
Medium Priority
?
1,933 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 1500 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 1500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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