1
For educational purposes, I was observing the property User class Controller of Asp.Net MVC.
I saw a example, very interesting, that a base class for the controllers has been implemented and it owns the property Currentuser:
public abstract class AppController : Controller
{
public AppUserPrincipal CurrentUser {
get { return new AppUserPrincipal(base.User as ClaimsPrincipal); }
}
}
That property User is apparently the same as in Asp.Net Webforms, of which I know nothing either.
The estate User is the type Iprincipal and that implements a property of the type Iidentity and a method bool IsInRole(string role)
.
In turn, Claimsprincipal inherits from Iprincipal, suggesting why the cast on the property Currentuser it is possible.
But the property even returns is a type Appuserprincipal which, despite the name, inherits from Claimsprincipal and apply some properties:
public class AppUserPrincipal : ClaimsPrincipal
{
public AppUserPrincipal(ClaimsPrincipal principal): base(principal) { }
public string Name {
get { return this.FindFirst(ClaimTypes.Name).Value; }
}
public string Country {
get { return this.FindFirst(ClaimTypes.Country).Value; }
}
}
Well, all this so far was just to show a little bit where I walked and then facilitate the understanding of my doubts.
Doubts that because I’m still a total Newbie in the world of languages Microsoft and the environment .Net. In addition to not having understood yet the structure of the classes and interfaces of the Asp.Net Identity and how he works. Before I only programmed for desktop with Delphi and many doubts were solved easily by being able to access the fonts of the classes, methods and functions and see how they were written.
Anyway, I’m not one to use things with constancy and tranquility that I don’t understand. So those are the doubts:
- What is the property User of Controller of Asp.Net Mvc and, it is the same thing as that of a Webform? What is its purpose?
- The estate User stores logged-in user information? Stores in cookie or session?
- If I inherit my Identity user can get your instance through a cast? Or is it not necessary because there would be another way?
- The question about the User property storing a user instance comes, too, from the method
bool IsInRole(string role)
of the interface Iprincipal. How do I know the roles a user has will be there? How and where this is done?
Stay on it for now so we don’t make the answers too big.