RoleProvider question -- help please (.NET 2.0)

B

Burak Gunay

Hello,

I derived a custom provider from the provider class. I set

cookieless="UseUri"

in the web.config, because we don't want data stored on client
machines.

Now, as I understand it, the information from the Membership Provider
gets serialized and saved on the url, but the same does not apply to
the RoleProvider info.

Everytime a page with <asp:loginview> is called, the Role Provider page
gets called and the database gets queried, whereas the database does
not need to be queried again for user info by the Membership Provider,
since the info is saved on the url.

I tried to save the roles() as a session variable in the Role Provider
page but since that page is a vb class, it does not recognize the
Session class.

How can we save the roles() info so that we don't have to call the Role
Provider each time to figure out the roles assigned to a user?

Thanks,

Burak
 
E

Erik Funkenbusch

How can we save the roles() info so that we don't have to call the Role
Provider each time to figure out the roles assigned to a user?

By default, asp.net caches the roles for the current user, so it will call
your providers GetRolesForUser() method once and only once for the session,
after that it will return cached results.
 
B

Burak Gunay

Erik,

Are you sure about that? I have the following setting in my web.config

<membership defaultProvider="MyMembershipProvider">
<providers>
<clear/>
<add name="MyMembershipProvider"
type="MyMembershipProvider"></add>
</providers>
</membership>

and it calls the GetRolesForUser() method every time a page with a
loginview control comes up.

When I set the cookies on as follows

<roleManager defaultProvider="MyRoleProvider" enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPXROLES"
cookiePath="/"
cookieTimeout="30"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
createPersistentCookie="false"
cookieProtection="All" >

then it calls GetRolesForUser() only once.

Burak
 
E

Erik Funkenbusch

Erik,

Are you sure about that? I have the following setting in my web.config
....

and it calls the GetRolesForUser() method every time a page with a
loginview control comes up.

Correct. It has to call GetRolesForUser the first time (ie, when he logs
in), but after that, whenever UserPrincipal.IsInRole is called, it uses the
cached version.
 
E

Erik Funkenbusch

Correct. It has to call GetRolesForUser the first time (ie, when he logs
in), but after that, whenever UserPrincipal.IsInRole is called, it uses the
cached version.

Sorry, I reread this and realized you were talking about something else. I
haven't looked at the LoginView control yet, but it may be calling
GetRolesForUser() directly rather than using IsInRole
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top