Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend the asp.net User.Identity Property?

Tags:

c#

asp.net

I'm not talking about asp.net membership.

For each logged user I want to cache some properties like status or the number of friend requests, from the db.

I can create custom class which would do it but I thought it will be better to extend the existing User.Identity property.
Something like this:

Label1.Text = User.Identity.Status;

It is possible?

like image 830
Adir Avatar asked Feb 26 '23 13:02

Adir


1 Answers

It is possible by defining your own IIdentity (and possibly IPrincipal too) and constructing this when creating the IPrincipal for the HTTP request. I believe the correct place to do this is when the PostAuthenticateRequest event is raised.

The answers on this other stackoverflow question explain how to do it - ASP.NET set custom identity or principal (it says for MVC but both go through the same processing pipeline).

like image 184
Russ Cam Avatar answered Mar 08 '23 16:03

Russ Cam