Getting the current user object asp.net MVC 5 -


I am confused about user authentication in ASP.NET MVC5 ... I am referring to this article:

And this question:

... and know exactly where the code is in my identity identity code here < / P>

  namespace attempt CS_INSTRUCTION. Models {public class ApplicationUser: IdentityUser {public string first name {get; Set; }} Public Sector MyUserStore: IUserStore & lt; ApplicationUser & gt; {} Public Square ApplicationDbContext & lt; ApplicationUser & gt; : IdentityDbContext & lt; ApplicationUser & gt; {Public ApplicationDbContext (): Base ("DefaultConnection") {}}}  

And in the controller I am trying to get UserObject with this:

  Var User Manager = New User Manager & lt; ApplicationUser & gt; (New MyUserStore & lt; ApplicationUser & gt; (New ApplicationDbContext ())); Var user = userManager.FindById (User.Identity.GetUserId ());  

This gives me the most compilation errors in the form of effort_4. Models MyUserStore & lt; ApplicationUser & gt; The 'Interface Member' system.Idcopy does not apply to DISASS () , but it is also saying that ApplicationUser can not be used as type parameter 'TUUSER'.

Currently I am using:

  var id = User.Identity.GetUserId (); Var user = db.users.first (x = & gt; x.Id == ID);  

This may not be the best way, there is no doubt that due to [authorize] DB was already inquired. I do not need anything involved in roles or some fancy ... just to expand the user model and it should be able to refer to other stuff: db.Apartments.where (apt = & Gt; apt.OwnerId == Current User ID) . She said, what is the best practice to add tables to the user table? Do I have an integer ID in the ApplicationUser class for the query? Or should I just use the Gide?

You are getting an error because you have defined the interface (IUserStore) that you defined as your own If you do not need to create userstore, you can use one that uses the box:

  New UserManager & lt; ApplicationUser & gt; (New UserStore & lt; ApplicationUser & gt; (New ApplicationDbContext ()))  

If it does not meet your needs, then your own implementation methods of ASP.NET identity But this is a great guide:

Besides, I believe that [authorized] is authorizing the user's cookie, not inquiring the database in any way is.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -