I'm trying to use the MVC Identity code from a desktop application. The desktop application needs to make a bunch of additions and updates to my user data.
I have copied the classes over from a generated MVC application, installed the required packages and made all changes necessary for the code to compile.
The only problem I have now is creating an instance of the ApplicationUserManager
class.
public ApplicationUserManager UserManager
{
get => _userManager ?? HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
private set
{
_userManager = value;
}
}
private ApplicationUserManager _userManager;
The problem is I have no HttpContext
, and so HttpContext.Current
will always return null.
Is what I'm doing possible? How can I build a UserManager
from a desktop application without an HTTP context?
UPDATE:
I have direct access to the database, so I'd be happy with a solution that didn't require the Identity code and classes. The biggest hurdle here would be creating and updating passwords so that they can be "understood" by the Identity code in my website app.
MVC is UI platform agnostic. You can do web, voice, desktop or console apps.
interesting approach,
otherwise, it will be necessary to clean out everything that httpcontext touches..
you can create ApplicationUserManager instance like this.
public ApplicationUserManager UserManager
{
get
{
if(_userManager == null)
{
_userManager = new ApplicationUserManager(new Microsoft.AspNet.Identity.EntityFramework.UserStore<ApplicationUser>(yourDbContext));
}
return _userManager;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With