Trying to create basic authentication in a WebForm .net 4.5 with Individual auth, C#
The system now sort of works, except when you run the Register page, it only asks for EMAIL, PASSWORD, PASSWORD (verify). Why is the UserName stuck as the email? Im so used to MVC world, am just not getting why this wont work. After an email registers,
if I change the username in the table to 'fred' and try to login, it FAILS.
What is needed to add a real UserName entry?
public partial class Register : Page
{
protected void CreateUser_Click(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
IdentityResult result = manager.Create(user, Password.Text);
if (result.Succeeded)
{
It's just a starting point. IMO this is just to provide a simple template that works. if you add this field, handle what to do if taken already by someone else and maybe change this at a later time, it seems it could be enough.
Trying to create basic authentication in a WebForm .net 4.5 with Individual auth, C#
The system now sort of works, except when you run the Register page, it only asks for EMAIL, PASSWORD, PASSWORD (verify). Why is the UserName stuck as the email? Im so used to MVC world, am just not getting why this wont work. After an email registers,
if I change the username in the table to 'fred' and try to login, it FAILS.
What is needed to add a real UserName entry?
public partial class Register : Page
{
protected void CreateUser_Click(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
IdentityResult result = manager.Create(user, Password.Text);
if (result.Succeeded)
{
It's just a template and you can change the markup any way you like.
If you do not want the email used as the username and email address then simply update the code. This assumes you added a Username textbox to the registration form.
var user = new ApplicationUser() { UserName = Username.Text, Email = Email.Text };
Yes its a template, but I modified just as you did, try to run?
Unable to find control id 'Text' referenced by the 'ControlToValidate' property of ''.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to find control id 'Text' referenced by the 'ControlToValidate' property of ''.
But need to control the UserName, because im going to validate against a custom table. shouldnt be so difficult. Its got to be the .aspx code
mgebhard
rogersbr
Trying to create basic authentication in a WebForm .net 4.5 with Individual auth, C#
The system now sort of works, except when you run the Register page, it only asks for EMAIL, PASSWORD, PASSWORD (verify). Why is the UserName stuck as the email? Im so used to MVC world, am just not getting why this wont work. After an email registers,
if I change the username in the table to 'fred' and try to login, it FAILS.
What is needed to add a real UserName entry?
public partial class Register : Page
{
protected void CreateUser_Click(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
IdentityResult result = manager.Create(user, Password.Text);
if (result.Succeeded)
{
It's just a template and you can change the markup any way you like.
If you do not want the email used as the username and email address then simply update the code. This assumes you added a Username textbox to the registration form.
var user =newApplicationUser(){UserName=Username.Text,Email=Email.Text};
Well Im getting closer. I have the page where it will accept a username now, but the stored password login FAILS. I register, password and all, confirm, it accepts it from the email, says confirmed now login? click and the password is rejected or login
rejected.
It didnt even write the newly registered account in the table. at all
OMG, has some delay issue. it shouldve worked, didnt, somehow had to refresh something like the table itself because after a delay it works. so the username is storing fine, it seems to login.
but dont know why I put the changes, ran, didnt work. end up putting back those same changes and then it does work. so for now the problem has to do with it refreshing something, or not refreshing and getting an error, then blink and it works.
So it looks like there is a timing issue. Does there need to be Await style access to the table?? It gets the records back, the email is in there but it doesnt see it?
protected void Forgot(object sender, EventArgs e)
{
if (IsValid)
{
// Validate the user's email address
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
ApplicationUser user = manager.FindByName(Email.Text);
if (user == null || !manager.IsEmailConfirmed(user.Id))
{
FailureText.Text = "The user either does not exist or is not confirmed.";
ErrorMessage.Visible = true;
return;
}
// F
The Id in user.Id throws a null reference exception.
And manager.FindByName(Email.Text) does not work, it returns null when you can see the results view showing the 2 currently registered users, the email.text matches but the code fails, saying NULL? then drops into the failuretext.text.
confirmed. the user manager fails to consistently see stored emails.
Put this in a try/catch, it cannot verify emails that are clearly there, so unless there is some cause this looks like a bug in the boilerplate code
The code below finds a user by username not email address. Remember you specifically wanted a separate email and unsername which is how we got to this point.
ApplicationUser user = manager.FindByName(Email.Text);
I strongly recommend that you read the reference documents so that you know what methods are available and how they work. I provided the following link a previous post.
You are right, thanks! So I saw how it said FindByName, but then assumed it was using "Name" in a generalized way. Im studying the links, also select the method names or other names and right click/peek help.
makes alot more sense now and it works
mgebhard
rogersbr
confirmed. the user manager fails to consistently see stored emails.
Put this in a try/catch, it cannot verify emails that are clearly there, so unless there is some cause this looks like a bug in the boilerplate code
The code below finds a user by username not email address. Remember you specifically wanted a separate email and unsername which is how we got to this point.
ApplicationUser user = manager.FindByName(Email.Text);
I strongly recommend that you read the reference documents so that you know what methods are available and how they work. I provided the following link a previous post.
Member
126 Points
873 Posts
Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email address?
Dec 12, 2018 04:01 PM|rogersbr|LINK
Trying to create basic authentication in a WebForm .net 4.5 with Individual auth, C#
The system now sort of works, except when you run the Register page, it only asks for EMAIL, PASSWORD, PASSWORD (verify). Why is the UserName stuck as the email? Im so used to MVC world, am just not getting why this wont work. After an email registers, if I change the username in the table to 'fred' and try to login, it FAILS.
What is needed to add a real UserName entry?
public partial class Register : Page { protected void CreateUser_Click(object sender, EventArgs e) { var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>(); var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text }; IdentityResult result = manager.Create(user, Password.Text); if (result.Succeeded) {
All-Star
48570 Points
18086 Posts
Re: Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email addre...
Dec 12, 2018 04:33 PM|PatriceSc|LINK
Hi,
It's just a starting point. IMO this is just to provide a simple template that works. if you add this field, handle what to do if taken already by someone else and maybe change this at a later time, it seems it could be enough.
All-Star
53141 Points
23684 Posts
Re: Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email addre...
Dec 12, 2018 04:36 PM|mgebhard|LINK
It's just a template and you can change the markup any way you like.
If you do not want the email used as the username and email address then simply update the code. This assumes you added a Username textbox to the registration form.
Member
126 Points
873 Posts
Re: Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email addre...
Dec 12, 2018 06:54 PM|rogersbr|LINK
Yes its a template, but I modified just as you did, try to run?
But need to control the UserName, because im going to validate against a custom table. shouldnt be so difficult. Its got to be the .aspx code
Member
126 Points
873 Posts
Re: Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email addre...
Dec 12, 2018 07:09 PM|rogersbr|LINK
Well Im getting closer. I have the page where it will accept a username now, but the stored password login FAILS. I register, password and all, confirm, it accepts it from the email, says confirmed now login? click and the password is rejected or login rejected.
It didnt even write the newly registered account in the table. at all
OMG, has some delay issue. it shouldve worked, didnt, somehow had to refresh something like the table itself because after a delay it works. so the username is storing fine, it seems to login.
but dont know why I put the changes, ran, didnt work. end up putting back those same changes and then it does work. so for now the problem has to do with it refreshing something, or not refreshing and getting an error, then blink and it works.
Member
126 Points
873 Posts
Re: Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email addre...
Dec 12, 2018 07:25 PM|rogersbr|LINK
So it looks like there is a timing issue. Does there need to be Await style access to the table?? It gets the records back, the email is in there but it doesnt see it?
protected void Forgot(object sender, EventArgs e) { if (IsValid) { // Validate the user's email address var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); ApplicationUser user = manager.FindByName(Email.Text); if (user == null || !manager.IsEmailConfirmed(user.Id)) { FailureText.Text = "The user either does not exist or is not confirmed."; ErrorMessage.Visible = true; return; } // F
The Id in user.Id throws a null reference exception.
And manager.FindByName(Email.Text) does not work, it returns null when you can see the results view showing the 2 currently registered users, the email.text matches but the code fails, saying NULL? then drops into the failuretext.text.
Member
126 Points
873 Posts
Re: Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email addre...
Dec 12, 2018 07:46 PM|rogersbr|LINK
confirmed. the user manager fails to consistently see stored emails.
Put this in a try/catch, it cannot verify emails that are clearly there, so unless there is some cause this looks like a bug in the boilerplate code
All-Star
53141 Points
23684 Posts
Re: Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email addre...
Dec 12, 2018 08:13 PM|mgebhard|LINK
The code below finds a user by username not email address. Remember you specifically wanted a separate email and unsername which is how we got to this point.
https://docs.microsoft.com/en-us/previous-versions/aspnet/mt151639%28v%3dvs.108%29
If you want to find a user by email address then use the appropriate UserManager method.
https://docs.microsoft.com/en-us/previous-versions/aspnet/mt151641%28v%3dvs.108%29
I strongly recommend that you read the reference documents so that you know what methods are available and how they work. I provided the following link a previous post.
https://docs.microsoft.com/en-us/previous-versions/aspnet/dn613290(v%3dvs.108)
Member
126 Points
873 Posts
Re: Why is the default boilerplate asp.net Register.aspx.cs code force the UserName = email addre...
Dec 13, 2018 04:13 AM|rogersbr|LINK
You are right, thanks! So I saw how it said FindByName, but then assumed it was using "Name" in a generalized way. Im studying the links, also select the method names or other names and right click/peek help.
makes alot more sense now and it works