I have implemented a custom IPrincipal that I set in
protected void Application_PostAuthenticateRequest(Object开发者_运维知识库 sender, EventArgs args)
by doing
Context.User = GetCustomPrincipal(User.Identity);
Thread.CurrentPrincipal = Context.User;
But my custom principal hits the database and gets custom information about the user. I don't want it hitting the database repeatedly for every request.
What is the best way to cache this? I was thinking of storing it in the Session, is that a good idea?
EDIT: Stupid me. Session is not even available in this method, should have tested before posting the question.
But question still remains..
The standard approach is to store the data in the auth cookie. If you aren't using cookies, you can store the data in session.
精彩评论