Using Owin Identity programs and I am having problems with three items ApplicationUserManager, PhoneNumber and IdentifyHelper. The file is a verifyphone number aspx.cs file. The addphonenumber file is fine. Below is the code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
namespace Bmples.Account
{
public partial class VerifyPhoneNumber : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var phonenumber = Request.QueryString["PhoneNumber"];
var code = manager.GenerateChangePhoneNumberToken(User.Identity.GetUserId(), phonenumber);
PhoneNumber.Value = phonenumber;
}
protected void Code_Click(object sender, EventArgs e)
{
if (!ModelState.IsValid)
{
ModelState.AddModelError("", "Invalid code");
return;
}
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var result = manager.ChangePhoneNumber(User.Identity.GetUserId(), PhoneNumber.Value, Code.Text);
if (result.Succeeded)
{
var user = manager.FindById(User.Identity.GetUserId());
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "Failed to verify phone");
}
}
}
I don't understand why I am having so many Owin Identy problems. I have solved the rest but can't get this one/ The error says that I am missing a directive or assembly. I copied the file from the Microsoft Wingtop program and there were no problems.
Generally speaking I would suggest to use VS Object Explorer. You can search a class and find in which namespace it is defined (or use "search in all files" ?). If it fails do that in the app from which you copied this to see if you missed copying some source
code or if maybe you used a DLL ?
It's very helpful when the actual error is posted with the line that caused the error. Otherwise we have to look through the code, which is not formatted by the way, and guess.
Please post the error message and line of code that causes the error. For reference, there is an Insert/Edit Code button in the Message toolbar. It looks like this...
{;}
Use this feature when posting code as it makes it easier to read.
One this I see with the code there's redundancy. The Page_Load event has local UserManager and there's page class UserManager. I recommend creating basic web project that uses the standard Web Forms with Individual Account option. Use this project as
a template that shows how to use Identity.
Thank you I am sorry that I did not show you the mistake and also did not know there was a special thing to put in next to the mistake. I also do not see the duplicate. I do see that I should not have added everything after the helpers.
Here is the paragraph with the mistake.
public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie); (It is in this line Create Identity)
// Add custom user claims here
return userIdentity;
}
I did read a lot about the applications user managers and was able to fix other parts of this programmer but could not do it with this one.
I am not a programmer just trying to update my old site and I was using Microsoft wingtop and even with changes the errors have popped up.
I have fixed the create identity but I have another problem in identity mode. Here is the problem.
public static implicit operator ApplicationDbContext(Bumples.ApplicationDbContext v) (*ApplicationDBContext has the error Does not exist in the name space am I missing a directive or assembly)
{
throw new NotImplementedException();
}
I had added 2 statements in Identity conf..cs which I took out and the create identity above was fixed. Below is what I took out of identity config
Member
9 Points
214 Posts
Get OwinContext problems
Oct 19, 2018 04:00 PM|bumples18|LINK
Using Owin Identity programs and I am having problems with three items ApplicationUserManager, PhoneNumber and IdentifyHelper. The file is a verifyphone number aspx.cs file. The addphonenumber file is fine. Below is the code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
namespace Bmples.Account
{
public partial class VerifyPhoneNumber : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var phonenumber = Request.QueryString["PhoneNumber"];
var code = manager.GenerateChangePhoneNumberToken(User.Identity.GetUserId(), phonenumber);
PhoneNumber.Value = phonenumber;
}
protected void Code_Click(object sender, EventArgs e)
{
if (!ModelState.IsValid)
{
ModelState.AddModelError("", "Invalid code");
return;
}
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var result = manager.ChangePhoneNumber(User.Identity.GetUserId(), PhoneNumber.Value, Code.Text);
if (result.Succeeded)
{
var user = manager.FindById(User.Identity.GetUserId());
if (user != null)
{
IdentityHelper.SignIn(manager, user, false);
Response.Redirect("/Account/Manage?m=AddPhoneNumberSuccess");
}
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "Failed to verify phone");
}
}
}
I don't understand why I am having so many Owin Identy problems. I have solved the rest but can't get this one/ The error says that I am missing a directive or assembly. I copied the file from the Microsoft Wingtop program and there were no problems.
Thank, Jen
All-Star
48280 Points
17982 Posts
Re: Get OwinContext problems
Oct 19, 2018 04:40 PM|PatriceSc|LINK
Hi,
You are using a "standard" template ? Try maybe https://forums.asp.net/t/1981988.aspx?ASP+NET+Identity+2+0+Where+is+ApplicationUserManager+
Generally speaking I would suggest to use VS Object Explorer. You can search a class and find in which namespace it is defined (or use "search in all files" ?). If it fails do that in the app from which you copied this to see if you missed copying some source code or if maybe you used a DLL ?
All-Star
52091 Points
23224 Posts
Re: Get OwinContext problems
Oct 19, 2018 04:57 PM|mgebhard|LINK
It's very helpful when the actual error is posted with the line that caused the error. Otherwise we have to look through the code, which is not formatted by the way, and guess.
Please post the error message and line of code that causes the error. For reference, there is an Insert/Edit Code button in the Message toolbar. It looks like this...
Use this feature when posting code as it makes it easier to read.
One this I see with the code there's redundancy. The Page_Load event has local UserManager and there's page class UserManager. I recommend creating basic web project that uses the standard Web Forms with Individual Account option. Use this project as a template that shows how to use Identity.
Member
9 Points
214 Posts
Re: Get OwinContext problems
Oct 19, 2018 06:04 PM|bumples18|LINK
Thank you I am sorry that I did not show you the mistake and also did not know there was a special thing to put in next to the mistake. I also do not see the duplicate. I do see that I should not have added everything after the helpers.
Here is the paragraph with the mistake.
public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie); (It is in this line Create Identity)
// Add custom user claims here
return userIdentity;
}
I did read a lot about the applications user managers and was able to fix other parts of this programmer but could not do it with this one.
I am not a programmer just trying to update my old site and I was using Microsoft wingtop and even with changes the errors have popped up.
Thanks Jen
Member
9 Points
214 Posts
Re: Get OwinContext problems
Oct 20, 2018 02:00 AM|bumples18|LINK
I have fixed the create identity but I have another problem in identity mode. Here is the problem.
public static implicit operator ApplicationDbContext(Bumples.ApplicationDbContext v) (*ApplicationDBContext has the error Does not exist in the name space am I missing a directive or assembly)
{
throw new NotImplementedException();
}
I had added 2 statements in Identity conf..cs which I took out and the create identity above was fixed. Below is what I took out of identity config
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
There was someone else on this thread that I have lost that sent me back to identity config to check. I have lost his name.
Thanks for your help and the other person.
Jen
Member
9 Points
214 Posts
Re: Get OwinContext problems
Oct 22, 2018 12:57 AM|bumples18|LINK
Thank you for all of your help. I am not a programmer but trying to get my site back online and appreciate all the help I am getting.
Jen