I am following Microsoft's example to do email validation using Identity 2.0.0
I'm stuck in this part
public ApplicationUserManager UserManager { get { return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); } private set { _userManager = value; } }
This works in the controller , but the HttpContext does not contain any GetOwinContext method in ApiController .
So, I tried HttpContext.Current.GetOwinContext() , but the GetUserManager method GetUserManager not exist.
I cannot figure out how to get the UserManager that I create in Startup.Auth.cs
this line
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
calls the following function to configure UserManager
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) { var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>())); //Configure validation logic for usernames manager.UserValidator = new UserValidator<ApplicationUser>(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure user lockout defaults manager.UserLockoutEnabledByDefault = true; manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5); manager.MaxFailedAccessAttemptsBeforeLockout = 5; manager.EmailService = new EmailService(); var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity")); } return manager; }
How can I access this UserManager in ApiController ?
c # asp.net-web-api asp.net-identity owin
Marc Jun 02 '14 at 18:48 2014-06-02 18:48
source share