Cast User object in ASP.NET Identity 2.0 -


I want to get a custom ApplicationUser example in the controller. Can I get from the user object inside the controller? How should I do this?

I tried to do it but it did not work:

  ApplicationUser u = (ApplicationUser) user; ApplicationUser u2 = (ApplicationUser) User.Identity;  

My custom identifier model happens in this way:

  public class ApplicationUser: IdentityUser & lt; Long, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim & gt; {Receive public virtual user information user information; Set; } Public async works & lt; Identity of the claim & gt; GenerateUserIdentityAsync (ApplicationUserManager manager) {// NOTE: Authentication type should match one // defined in cookieaccountation. the option. AuthenticationType var userIdentity = Wait Manager. CreateIdentityAsync (this, DefaultAuthenticationTypes.ApplicationCookie); // Include custom user claims here. Users return the identity; }} Public Class ApplicationRole: Identity Reel & lt; Long, ApplicationUserRole & gt; {Public ApplicationRole (): Base () {} Public ApplicationRole (string name, string description) {this.Name = name; this. Description = description; } Public Virtual String Description {get; Set; }} Public class ApplicationUserRole: IdentityUserRole & lt; Long & gt; {} Public class ApplicationUserClaim: IdentityUserClaim & lt; Long & gt; {} Public class ApplicationUserLogin: IdentityUserLogin & lt; Long & gt; {}  

No controller's user property returns an IPrincipal object, not an ApplicationUser object . These two completely separate things are the IPrincipal used by ASP.NET to control authentication and authorization, while ApplicationUser is the only unit used in your database.

If you want ApplicationUser, you will need to get it from User Manager.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -