locked
System Invalid Operation excepts. No Owin Environment was found in the context. RRS feed

  • Question

  • User-605499000 posted

    I am getting this error in both the registry and the login below is the line

    var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();

    Here is the program and also what I put in the web config file

    using Jen19.Models;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Microsoft.AspNet.Identity.Owin;
    using System;
    using System.Linq;
    using System.Web;
    using System.Web.UI;

    namespace Jen19.Account
    {
    public partial class Register : Page
    {
    protected void CreateUser_Click(object sender, EventArgs e)
    {
    var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();  ** here is the line
    var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
    IdentityResult result = manager.Create(user, Password.Text);
    if (result.Succeeded)
    {
    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
    //string code = manager.GenerateEmailConfirmationToken(user.Id);
    //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
    //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

    IdentityHelper.SignIn(manager, user, isPersistent: false);


    using (Jen19.Logic.ShoppingCartActions usersShoppingCart = new Jen19.Logic.ShoppingCartActions())
    {
    String cartId = usersShoppingCart.GetCartId();
    usersShoppingCart.MigrateCart(cartId, user.Id);
    }

    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
    }
    else
    {
    ErrorMessage.Text = result.Errors.FirstOrDefault();
    }
    }
    }
    }

    web confi 2 lines

    <appSettings>
    <add key="owin:AppStartup" value="Jen19.Startup, Jen19" />
    <add key="owin:AutomaticAppStartup" value="true" />
    </appSettings>

    I am using wintip toys as my source for the most of the web files.  What do I need to do?

    Thanks,

    Jen

    Thursday, June 27, 2019 9:14 PM

All replies

  • User-719153870 posted

    Hi bumples18,

    I made a demo based on the code provided, but couldn't reproduce your problem.

    I also have tried to modify the contents of Web.config and startup.cs, still can't reproduce your problem.

    In my opinion, the problem is likely to arise in web.config and Startup.cs.

    It would be helpful if you could provide the code in Startup. CS under your project.

    Or you can refer to:https://stackoverflow.com/questions/18232549/no-owin-environment-item-was-found-in-the-context

    Below is codes of my demo:

    ASPX:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="Email" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
                <asp:TextBox ID="Password" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
                <asp:Button ID="CreateUser" runat="server" Text="CreateUser" OnClick="CreateUser_Click" />
                <asp:Label ID="ErrorMessage" runat="server" Text="ErrorMessage"></asp:Label>
            </div>
        </form>
    </body>
    </html>

    CS:

     protected void CreateUser_Click(object sender, EventArgs e)
            {
                var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); //here is the line
                var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
                IdentityResult result = manager.Create(user, Password.Text);
                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    //string code = manager.GenerateEmailConfirmationToken(user.Id);
                    //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                    //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
    
                    //IdentityHelper.SignIn(manager, user, isPersistent: false);
    
                    Logic.ShoppingCartActions usersShoppingCart = new Logic.ShoppingCartActions();
                    String cartId = usersShoppingCart.GetCartId();
                    usersShoppingCart.MigrateCart(cartId, user.Id);
    
                    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                }
                else
                {
                    ErrorMessage.Text = result.Errors.FirstOrDefault();
                }
            }

    Here is result of my demo:

    Best Regard,

    Yang Shen

    Friday, June 28, 2019 6:02 AM
  • User-605499000 posted

    Thank you for getting back to me.  I am afraid that it is still not working.  I put in what you suggested and also read the other things you said to look at.  

    Below is the startup.cs and also the StartupAuth.cs

    using Microsoft.Owin;
    using Owin;

    [assembly: OwinStartupAttribute(typeof(Jen19.Startup))]
    namespace Jen19
    {
    public partial class Startup
    {
    public void Configuration(IAppBuilder app)
    {
    ConfigureAuth(app);

    using Jen19.Models;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin;
    using Microsoft.Owin.Security.Cookies;
    using Microsoft.Owin.Security.Google;
    using Owin;
    using System;


    namespace Jen19
    {
    public partial class Startup
    {

    // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301883
    public void ConfigureAuth(IAppBuilder app)
    {
    // Configure the db context, user manager and signin manager to use a single instance per request
    app.CreatePerOwinContext(ApplicationDbContext.Create);


    // Enable the application to use a cookie to store information for the signed in user
    // and to use a cookie to temporarily store information about a user logging in with a third party login provider
    // Configure the sign in cookie
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login"),
    Provider = new CookieAuthenticationProvider
    {
    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
    validateInterval: TimeSpan.FromMinutes(30),
    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
    }
    });
    // Use a cookie to temporarily store information about a user logging in with a third party login provider
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

    // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
    app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

    // Enables the application to remember the second login verification factor such as phone or email.
    // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
    // This is similar to the RememberMe option when you log in.
    app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

    // Uncomment the following lines to enable logging in with third party login providers
    //app.UseMicrosoftAccountAuthentication(
    // clientId: "",
    // clientSecret: "");

    //app.UseTwitterAuthentication(
    // consumerKey: "",
    // consumerSecret: "");

    //app.UseFacebookAuthentication(
    // appId: "",
    // appSecret: "");

    // app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
    // {
    // ClientId = "000000000000.apps.googleusercontent.com",
    // ClientSecret = "00000000000"
    //});
    }

    I also changed the web conf to false instead of true.  I couldn't open anything with true.

    My site is bumples.com but I have not put in register or login yet so I have a working program.

    I hope this helps and thanks again,

    Jen
    }
    }

    StartupAuth.cs


    }
    }
    }

    Friday, June 28, 2019 6:16 PM
  • User-719153870 posted

    Hi bumples18,

    In your Startup.Auth.cs, there are two codes related to 'manager' creation that do not exist, but exist in my file.

    You can try adding these two codes to see if they will help you with your problem.

    Below is my Startup.cs and Startup.Auth.cs:

    Startup.cs:

    using Microsoft.Owin;
    using Owin;
    
    [assembly: OwinStartupAttribute(typeof(WebformDemo04.Startup))]
    namespace WebformDemo04
    {
        public partial class Startup {
            public void Configuration(IAppBuilder app) {
                ConfigureAuth(app);
            }
        }
    }

    Startup.Auth.cs:

    using System;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin;
    using Microsoft.Owin.Security.Cookies;
    using Microsoft.Owin.Security.DataProtection;
    using Microsoft.Owin.Security.Google;
    using Owin;
    using WebformDemo04.Models;
    
    namespace WebformDemo04
    {
        public partial class Startup
        {
    
            // For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301883
            public void ConfigureAuth(IAppBuilder app)
            {
                // Configure the db context, user manager and signin manager to use a single instance per request
                app.CreatePerOwinContext(ApplicationDbContext.Create);
                app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
                app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
    
                // Enable the application to use a cookie to store information for the signed in user
                // and to use a cookie to temporarily store information about a user logging in with a third party login provider
                // Configure the sign in cookie
                app.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                    LoginPath = new PathString("/Account/Login"),
                    Provider = new CookieAuthenticationProvider
                    {
                        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                            validateInterval: TimeSpan.FromMinutes(30),
                            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                    }
                });
                // Use a cookie to temporarily store information about a user logging in with a third party login provider
                app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
    
                // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
                app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
    
                // Enables the application to remember the second login verification factor such as phone or email.
                // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
                // This is similar to the RememberMe option when you log in.
                app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
    
                // Uncomment the following lines to enable logging in with third party login providers
                //app.UseMicrosoftAccountAuthentication(
                //    clientId: "",
                //    clientSecret: "");
    
                //app.UseTwitterAuthentication(
                //   consumerKey: "",
                //   consumerSecret: "");
    
                //app.UseFacebookAuthentication(
                //   appId: "",
                //   appSecret: "");
    
                //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
                //{
                //    ClientId = "",
                //    ClientSecret = ""
                //});
            }
        }
    }
    

    If this still doesn't solve your problem, please keep in touch.

    Best Regard,

    Yang Shen

    Monday, July 1, 2019 1:34 AM
  • User-605499000 posted

    Thanks again. I put that into Startup Authority and still the same error. I checked the login and that takes me to OpenAuthProviders and I get the same exception error

    public IEnumerable<string> GetProviderNames()
    {
    return Context.GetOwinContext().Authentication.GetExternalAuthenticationTypes().Select(t => t.AuthenticationType); * error is on this line.
    }

    I  tried moving the whole account over to Jen19 from another account with no errors. I had to change all the accountusermanager to go from Models folder to Startup.Auth. which I did.  

    Still got the same error.  I have tried and read everything.  Do you have any other ideas? Do you think that If I move it to my site that I might not have the errors.

    Sorry to keep bothering you.  

    Jen

    Monday, July 1, 2019 10:10 PM
  • User-719153870 posted

    Hi bumples18,

    May you provide the version of your Identity.Owin? This might be helpful.

    You can see the version by right click your project-"Manage NuGet Packages..."-search for identity in "Installed".

    Please refer to mine:

    Best Regard,

    Yang Shen

    Tuesday, July 2, 2019 7:14 AM
  • User-605499000 posted

    It is Microsoft.Aspnet.Identity.Owin version 2.22

    Are you using Owin or should I get out of Owin and find another register login program.

    Thanks,

    Jen

    Tuesday, July 2, 2019 2:14 PM
  • User-719153870 posted

    Hi bumples18,

    I'm sorry we still haven't solve your problem. If possible, please share all codes in below files in your project with me:

    IdentityConfig.cs and Startup.Auth.cs in App_Start

    IdentityModels.cs in Models

    Startup.cs

    Best Regard,

    Yang Shen

    Wednesday, July 3, 2019 8:38 AM
  • User-605499000 posted

    Hi below are the files that you asked for  and please don't apologize. I am so thankfor for the help. I have tried everything.

    IdentityConfig.cs

    using System;
    using System.Security.Claims;
    using System.Threading.Tasks;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin;
    using Microsoft.Owin.Security;
    using Jen19.Models;

    namespace Jen19
    {
    public class EmailService : IIdentityMessageService
    {
    public Task SendAsync(IdentityMessage message)
    {
    // Plug in your email service here to send an email.
    return Task.FromResult(0);
    }
    }

    public class SmsService : IIdentityMessageService
    {
    public Task SendAsync(IdentityMessage message)
    {
    // Plug in your SMS service here to send a text message.
    return Task.FromResult(0);
    }
    }

    // Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.
    public class ApplicationUserManager : UserManager<ApplicationUser>
    {
    public ApplicationUserManager(IUserStore<ApplicationUser> store)
    : base(store)
    {
    }

    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 validation logic for passwords
    manager.PasswordValidator = new PasswordValidator
    {
    RequiredLength = 6,
    RequireNonLetterOrDigit = true,
    RequireDigit = true,
    RequireLowercase = true,
    RequireUppercase = true,
    };

    // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
    // You can write your own provider and plug it in here.
    manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider<ApplicationUser>
    {
    MessageFormat = "Your security code is {0}"
    });
    manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<ApplicationUser>
    {
    Subject = "Security Code",
    BodyFormat = "Your security code is {0}"
    });

    // Configure user lockout defaults
    manager.UserLockoutEnabledByDefault = true;
    manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
    manager.MaxFailedAccessAttemptsBeforeLockout = 5;

    manager.EmailService = new EmailService();
    manager.SmsService = new SmsService();
    var dataProtectionProvider = options.DataProtectionProvider;
    if (dataProtectionProvider != null)
    {
    manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
    }
    return manager;
    }
    }

    public class ApplicationSignInManager : SignInManager<ApplicationUser, string>
    {
    public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager) :
    base(userManager, authenticationManager)
    { }

    public override Task<ClaimsIdentity> CreateUserIdentityAsync(ApplicationUser user)
    {
    return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);
    }

    public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
    {
    return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
    }
    }
    }

    Startup.Auth.cs

    using System;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin;
    using Microsoft.Owin.Security.Cookies;
    using Microsoft.Owin.Security.DataProtection;
    using Microsoft.Owin.Security.Google;
    using Owin;
    using Jen19.Models;

    namespace Jen19
    {
    public partial class Startup
    {

    // For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301883
    public void ConfigureAuth(IAppBuilder app)
    {
    // Configure the db context, user manager and signin manager to use a single instance per request
    app.CreatePerOwinContext(ApplicationDbContext.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

    // Enable the application to use a cookie to store information for the signed in user
    // and to use a cookie to temporarily store information about a user logging in with a third party login provider
    // Configure the sign in cookie
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login"),
    Provider = new CookieAuthenticationProvider
    {
    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
    validateInterval: TimeSpan.FromMinutes(30),
    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
    }
    });
    // Use a cookie to temporarily store information about a user logging in with a third party login provider
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

    // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
    app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

    // Enables the application to remember the second login verification factor such as phone or email.
    // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
    // This is similar to the RememberMe option when you log in.
    app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

    // Uncomment the following lines to enable logging in with third party login providers
    //app.UseMicrosoftAccountAuthentication(
    // clientId: "",
    // clientSecret: "");

    //app.UseTwitterAuthentication(
    // consumerKey: "",
    // consumerSecret: "");

    //app.UseFacebookAuthentication(
    // appId: "",
    // appSecret: "");

    //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
    //{
    // ClientId = "",
    // ClientSecret = ""
    //});
    }
    }
    }

    Startup.cs

    using Microsoft.Owin;
    using Owin;

    [assembly: OwinStartupAttribute(typeof(Jen19.Startup))]
    namespace Jen19
    {
    public partial class Startup
    {
    public void Configuration(IAppBuilder app)
    {
    ConfigureAuth(app);
    }
    }
    }

    IdentityModels.cs

    using System;
    using System.Security.Claims;
    using System.Threading.Tasks;
    using System.Web;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin.Security;
    using Jen19.Models;

    namespace Jen19.Models
    {
    // You can add User data for the user by adding more properties to your User class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
    public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager)
    {
    // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
    var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie);
    // Add custom user claims here
    return userIdentity;
    }

    public Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
    {
    return Task.FromResult(GenerateUserIdentity(manager));
    }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
    public ApplicationDbContext()
    : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
    return new ApplicationDbContext();
    }
    }
    }

    #region Helpers
    namespace Jen19
    {
    public static class IdentityHelper
    {
    // Used for XSRF when linking external logins
    public const string XsrfKey = "XsrfId";

    public static void SignIn(ApplicationUserManager manager, ApplicationUser user, bool isPersistent)
    {
    IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
    authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
    var identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
    authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
    }

    public const string ProviderNameKey = "providerName";
    public static string GetProviderNameFromRequest(HttpRequest request)
    {
    return request.QueryString[ProviderNameKey];
    }

    public const string CodeKey = "code";
    public static string GetCodeFromRequest(HttpRequest request)
    {
    return request.QueryString[CodeKey];
    }

    public const string UserIdKey = "userId";
    public static string GetUserIdFromRequest(HttpRequest request)
    {
    return HttpUtility.UrlDecode(request.QueryString[UserIdKey]);
    }

    public static string GetResetPasswordRedirectUrl(string code, HttpRequest request)
    {
    var absoluteUri = "/Account/ResetPassword?" + CodeKey + "=" + HttpUtility.UrlEncode(code);
    return new Uri(request.Url, absoluteUri).AbsoluteUri.ToString();
    }

    public static string GetUserConfirmationRedirectUrl(string code, string userId, HttpRequest request)
    {
    var absoluteUri = "/Account/Confirm?" + CodeKey + "=" + HttpUtility.UrlEncode(code) + "&" + UserIdKey + "=" + HttpUtility.UrlEncode(userId);
    return new Uri(request.Url, absoluteUri).AbsoluteUri.ToString();
    }

    private static bool IsLocalUrl(string url)
    {
    return !string.IsNullOrEmpty(url) && ((url[0] == '/' && (url.Length == 1 || (url[1] != '/' && url[1] != '\\'))) || (url.Length > 1 && url[0] == '~' && url[1] == '/'));
    }

    public static void RedirectToReturnUrl(string returnUrl, HttpResponse response)
    {
    if (!String.IsNullOrEmpty(returnUrl) && IsLocalUrl(returnUrl))
    {
    response.Redirect(returnUrl);
    }
    else
    {
    response.Redirect("~/");
    }
    }
    }
    }
    #endregion

    Thanks again for your help. 

    Jen

    Wednesday, July 3, 2019 10:37 PM
  • User-719153870 posted

    Hi bumples18,

    Thank you for all the above documents, but unfortunately we still can't solve your problem.

    I put the code you provided above into my test project, but the project is still working properly without reporting any errors that are same with yours.

    I guess your problem may be that your project can't start Owin environment successfully.

    You can try to put a break point in front of the following codes in your Startup.Auth.CS file and debug it.

    Normally, code at breakpoints is executed when the project start.

    If there are any unexpected in your project, please keep in touch.

    public partial class Startup
        {
    
            // For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301883
            public void ConfigureAuth(IAppBuilder app)
            {
                // Configure the db context, user manager and signin manager to use a single instance per request
                app.CreatePerOwinContext(ApplicationDbContext.Create);//Please put a break point here and then debug
                app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
                app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
    
                // Enable the application to use a cookie to store information for the signed in user
                // and to use a cookie to temporarily store information about a user logging in with a third party login provider
                // Configure the sign in cookie
                app.UseCookieAuthentication(new CookieAuthenticationOptions
                {
                    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                    LoginPath = new PathString("/Account/Login"),
                    Provider = new CookieAuthenticationProvider
                    {
                        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                validateInterval: TimeSpan.FromMinutes(30),
                regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                    }
                });
                // Use a cookie to temporarily store information about a user logging in with a third party login provider
                app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
    
                // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
                app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
    
                // Enables the application to remember the second login verification factor such as phone or email.
                // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
                // This is similar to the RememberMe option when you log in.
                app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
    
                // Uncomment the following lines to enable logging in with third party login providers
                //app.UseMicrosoftAccountAuthentication(
                // clientId: "",
                // clientSecret: "");
    
                //app.UseTwitterAuthentication(
                // consumerKey: "",
                // consumerSecret: "");
    
                //app.UseFacebookAuthentication(
                // appId: "",
                // appSecret: "");
    
                //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
                //{
                // ClientId = "",
                // ClientSecret = ""
                //});
            }
        }

    Best Regard,

    Yang Shen

    Thursday, July 4, 2019 6:54 AM
  • User-605499000 posted

    Thank you very much for all of your help and programs.  After reading your latest I took the day off to think abut my next move.

    Today I did some more reading about the problem and remembered that you said in the beginning that it usually a web problem. I went back to the web and made two changes and everything is working. Here are the two changes 

    <add key="owin:AutomaticAppStartup" value="true" /> made it true it was false

    <compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.6.1    added defaultLanguage=c#

    Hopefully that is the last major problem that I have. I am looking at your register again as I don't have a logout or manager account that is working. 

    Again thanks very much and I will mark it as done.

    Jen

    Friday, July 5, 2019 11:55 PM