When are User Roles Initialized?


J

Jonathan Wood

I've set up ASP.NET membership.

I can get the role(s) of the current user by calling
Roles.GetRolesForUser().

It seems like it would be a good idea to store some role-specific
calculations in the Session object so that I don't need to re-perform these
calculations for each page.

Questions:

1. Does storing data calculated from the current user's role in the Session
object seem like a good approach so I don't need to perform these
calculations again for each page?

2. Where would I do initialize this data? I tried placing code in the
LoggedIn event of my Login control. The problem is that
Roles.GetRolesForUser() seems to return an empty list at this point. I guess
it hasn't been initialized when this event is called. So where else could I
get it?

Thanks.
 
Ad

Advertisements

E

Eliyahu Goldin

Jonathan,

1. Yes, it does seem like a good approach.

2. It is a registered problem. It was discussed here
http://groups.google.com/group/micr...ork.aspnet/browse_frm/thread/2e546baadef642cf

Scott Guthrie explained the problem and offered a workaround:
The authentication principal won't get set until the next request to the
web-server. But you can use the "UserName" property on the Usercontrol
within the LoggedIn event to identify the user.

You can then use the Role APIs and pass the user name to retrieve their role
information.


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Ad

Advertisements

J

Jonathan Wood

Ah, appears to be just what I was looking for.

Many thanks!

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


Eliyahu Goldin said:
Jonathan,

1. Yes, it does seem like a good approach.

2. It is a registered problem. It was discussed here
http://groups.google.com/group/micr...ork.aspnet/browse_frm/thread/2e546baadef642cf

Scott Guthrie explained the problem and offered a workaround:
The authentication principal won't get set until the next request to the
web-server. But you can use the "UserName" property on the Usercontrol
within the LoggedIn event to identify the user.

You can then use the Role APIs and pass the user name to retrieve their
role information.


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Jonathan Wood said:
I've set up ASP.NET membership.

I can get the role(s) of the current user by calling
Roles.GetRolesForUser().

It seems like it would be a good idea to store some role-specific
calculations in the Session object so that I don't need to re-perform
these calculations for each page.

Questions:

1. Does storing data calculated from the current user's role in the
Session object seem like a good approach so I don't need to perform these
calculations again for each page?

2. Where would I do initialize this data? I tried placing code in the
LoggedIn event of my Login control. The problem is that
Roles.GetRolesForUser() seems to return an empty list at this point. I
guess it hasn't been initialized when this event is called. So where else
could I get it?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top