MVC var userStore = new UserStore(db); returning null

asp.net-identity asp.net-mvc c# entity-framework-6 usermanager

Question

I can´t figure it out, but I have two MVC projects with Single Sign On log in that I needed to reseed, and after the seed, userStore variable returns with a null value.

This is my code(note that the db works fine and finds all my tables and also the AspNetUsers table):

private ApplicationDbContext db = new ApplicationDbContext();

and in the Index method(userManager row throws the exception since userStore has null value):

        var userStore = new UserStore<ApplicationUser>(db);
        var userManager = new UserManager<ApplicationUser>(userStore);
        var userId = User.Identity.GetUserId();
        var user = userManager.FindById(userId);

I haven´t changed a single row of code between a working solution and the latest seed, but I added the SSO configuration between the last two seeds.

EDIT:

Tried to restart computer and the problem persists, but when I try logging in with another user, it works fine. When trying to login with the first user again i get another error:

The provided anti-forgery token was meant for a different claims-based user than the current user.

So I tried in a "InPrivate Window" and I get the original problem with the first user but any other user gets the anti-forgery error instead.

EDIT 2:

Tried running the project again and the original error occurs för the first user but the next I try logging in with throws the anti-forgery error.

After that trying to log in with another user, the first user also throws the anti-forgery error.

EDIT 3:

This specific behaviour seems to be connected to IE. In chrome and Firefox I get the original error, but I cant replicate any of the anti-forgery errors in any combination of order of logins or users, but the first user keeps getting original exception thrown.

So I guess it is the original error that is the problem for any browser.

EDIT 4:

Since I know the exact line of code that causes the problem, I think I can safely assume the following is related in some way.. I can set breakpoints on the following:

        var userStore = new UserStore<ApplicationUser>(db);
        var userManager = new UserManager<ApplicationUser>(userStore);

but can no longer set a breakpoint on this line:

        var userId = User.Identity.GetUserId();
1
0
4/20/2016 10:08:57 AM

Accepted Answer

Finally found the solution for me in another thread. I disabled this option:

Project Properties> Build> Optimize code

It fixed both the original problem and also the problem in the very end with breakpoints

0
4/21/2016 7:35:30 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow