Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to initialize information on authorization
    primarykey
    data
    text
    <p>Ok, so this seems like a common need. A little googling finds a lot of ways to do this. I'm interested in the most "mvc correct" way to do it.</p> <p>I have, in the upper right hand corner of my app, a greeting that says <code>Hello FirstName LastName</code>. Now, it's quite easy to get at the username of the logged in user, through the <code>IPrincipal</code> (aka <code>User.Identity.Name</code>). However, this won't give me the First and Last name of the user. I have to hit the Membership API to get that.</p> <p>Hitting the Membership API has its drawbacks. It hits the database every time, which adds an additional db access to every served page. It's easy enough to set some session variables on login, but this only works for that session. If the user clicks the "Remember me", then no login occurs next time and i have to still load these values.</p> <ol> <li>I could create my own membership provider to do some cacheing, but that's a lot of work for a more or less single purpose.</li> <li>I could use <code>Application_AuthenticateRequest</code> and hit the membership api and store the values in session variables, or something similar. This is ok, but seems a little brute force.</li> <li>I could register a global filter and handle OnAuthenticate, essentially doing the same thing. This seems a little better, but i'm unusre of the ramifications here.</li> <li>I could derive a base controller, and simly add properties to provide this information. This seems a bit "old school", and I hate having to make a base class for a single purpose.</li> <li>I could create a cacheing static method that would get the information on first access. This is basically not much better than a singleton.</li> <li>I could also create my own IPrincipal, but that means casting it every time to get at the data, and that seems clunky. I could wrap that in another class to simplify it, but still...</li> <li>I could store the data in the forms authentication cookie, and get it from there. There's some tools available to make that easier.</li> </ol> <p>Are there any methods I haven't thought of? And what is the most "mvc correct" way of doing it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload