Question

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..

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top