开发者

What is the best way to cache a custom IPrincipal for a asp.net mvc website?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜