Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 474k

ApplicationDbContext does not exist in current context?

Feb 24 2020 2:31 AM
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using Microsoft.Owin;  
  6. using Microsoft.AspNet.Identity;  
  7. using Microsoft.AspNet.Identity.Owin;  
  8. using Microsoft.Owin.Security.Cookies;  
  9. using Microsoft.Owin.Security.Google;  
  10. using Owin;  
  11. using eNtsaTrainingRegistration.Models;  
  12.   
  13. namespace eNtsaTrainingRegistration.App_Start  
  14. {  
  15.     public partial class Startup  
  16.     {  
  17.   
  18.         public void ConfigureAuth(IAppBuilder app)  
  19.         {  
  20.             // configure the db context, user manager and signin manager to a single instance per request.  
  21.   
  22.             app.CreatePerOwinContext(ApplicationDbContext);  
  23.             app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);  
  24.             app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);  
  25.             app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);  
  26.   
  27.   
  28.   
  29.             // Configure sign cookie.  
  30.             app.UseCookieAuthentication(new CookieAuthenticationOptions  
  31.             {  
  32.                 AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,  
  33.                 LoginPath = new PathString("/login"),  
  34.                 Provider = new CookieAuthenticationProvider  
  35.                 {  
  36.                     // Enables the application to validate the security stamp when the user logs in.  
  37.                     // This is a security feature which is used when you change a password or add an external login to your account.    
  38.                     OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(  
  39.                       validateInterval: TimeSpan.FromMinutes(30),  
  40.                       regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))  
  41.                 }  
  42.             });  
  43.             app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);  
  44.   
  45.             // Enables app to temperorily store user information when they are verified.  
  46.             app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));  
  47.   
  48.             // To remember when to login in.  
  49.             app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);  
  50.         }  
  51.   
  52.     }  
  53. }  

Answers (1)