title: Should I store a small picture avatar inside ClaimsIdentity in ASP.NET core? if not, what is the best way?
body: <p>I am new to ASP.NET core and I am developing a website (.NET core 2.1) with user login.</p>
  
  <p>I would like to be able to show an user avatar image in all pages that uses _Layout.cshtml.
  So inside that file, for the user name I am already using: <code>@User.Identity.Name</code>.
  Now I would like to use something like this: <code>@User.Claims.First("avatar")</code></p>
  
  <p>I am using Cookies based authentication:</p>
  
  <p>In my "Startup.cs":</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services) {
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  
      // support for cookie based authentication
      services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
          .AddCookie(options =&gt; {
              options.Cookie.HttpOnly = true;
              options.LoginPath = "/Account/Login";
          });
  }
  </code></pre>
  
  <p>In my "AccountController":</p>
  
  <pre><code>[HttpPost]
  public async Task&lt;IActionResult&gt; Login(LoginModel m) {
      var user = Authenticate(m.Email, m.Password); // returns null when authentication fails
      if (user!=null) {
          var userIdentity = new ClaimsIdentity(
              new List&lt;Claim&gt; {
                  new Claim(ClaimTypes.Name, user.Company.Name),
                  new Claim(ClaimTypes.Email, user.Email)
              }, "login");
          ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);
          await HttpContext.SignInAsync(principal);
          return Redirect("/"); // redirect after authentication
      }
      return View("Login"); // default view if cannot authenticate
  }
  </code></pre>
  
  <p>The avatar picture itself will be store in a firebase database, so I need to avoid database query for each page request of my website.</p>
  
  <p>Since "claims" are used for authorization rules, I don't feel like I should use that to store a "small" byte array that I can use to render a JPG picture. Since I am showing it in every page during the user session, I want to load the picture to the server RAM during the Login and make it stay there for as long as the user remains logged-in.</p>
  
  <p>I've found many examples where people will extend the class ClaimsPrincipal to add new properties, but that requires some other code change (seems to be related with IdentityModel using the entity framework) and a factory for ClaimsPrincipal objects. (If I have to take that direction, I would like a small example starting from the code I provided)</p>
  
  <p>Remembering that I am new to ASP.NET core MVC...
  If someone could point me towards a good direction I would appreciate.</p>