Why is [Owin] throwing a null exception on new project?

前端 未结 16 1353
孤城傲影
孤城傲影 2020-12-25 10:01

I have a rather strange issue i\'m not sure how to fix or if i can even fix it.

I\'ve done some research into the issue but can\'t find an answer to what\'s causing

相关标签:
16条回答
  • 2020-12-25 10:35

    After reading some answers, trying in IE instead of Chrome and seeing no crash, I just closed Chrome and restarted the app. It worked.

    0 讨论(0)
  • 2020-12-25 10:37

    Similar to Sandeep's answer, I also updated the cookie authentication provider. Except, instead of swallowing the error I threw the exception so you could see what the underlying problem was:

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login"),
        Provider = new CookieAuthenticationProvider
        {
            // Enables the application to validate the security stamp when the user logs in.
            // This is a security feature which is used when you change a password or add an external login to your account.  
            OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
                validateInterval: TimeSpan.FromMinutes(30),
                regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
    
                /* I changed this part */
                OnException = (context =>
                {
                    throw context.Exception;
                })
        }                
    });
    

    The underlying problem for me was that I had changed the model and forgotten to add a new migration.

    0 讨论(0)
  • 2020-12-25 10:37

    clear localhost cookies. if use firefox see this link. I have same error exactly and this solution here.

    0 讨论(0)
  • 2020-12-25 10:38

    I was getting similar error but when I changed EF configuration from DropCreateDatabaseIfModelChanges< Context> to DropCreateDatabaseAlways< Context>.

    I'm not sure about cause of your error but it seems like an issue in Katana Project https://katanaproject.codeplex.com/workitem/346

    You can try workaround at above link or from https://katanaproject.codeplex.com/discussions/565294

    This is what I did in my StartUp.Auth.cs

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login"),
        Provider = new CookieAuthenticationProvider
        {
               OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserManager, User>(
                validateInterval: TimeSpan.FromMinutes(1),
                regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
    
               //**** This what I did ***//
                OnException = context => { }
        }
    });
    
    0 讨论(0)
  • 2020-12-25 10:39

    Yes i had the same problem, i downloaded a database from Azure. I then change my app to use this My app had a new field that was not present in the azure backup Migrations were out of sync.

    Update-Database (in package manage with migrations enabled) did the trick.

    0 讨论(0)
  • 2020-12-25 10:40

    Try to remove the Migration from the project, it happened with me once I've enabled the database migration for the Identity DB

    after removing the entire migration folder and rebuild the problem disappeared

    it might work for you

    0 讨论(0)
提交回复
热议问题