I have a custom RoleProvider that I’m using, and I’ve found that cacheRolesInCookie isn’t working. After reading, this is expected behavior. However, I would like to override this and handle the cacheing on my own. My problem is that I can’t figure out how to read the value from the configuration file to determine if the cacheing should occur or not. Here is my config settings…
<roleManager defaultProvider="MyRoleProvider" cacheRolesInCookie="true" enabled="true">
<providers>
<clear/>
<add name="MyRoleProvider"
type="MyCompany.WebSecurity.MyRoleProvider"
connectionStringName="Security"
applicationName="TestSite" />
</providers>
</roleManager>
I read the provider settings using this code:
var membershipSection = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership");
var defaultProvider = membershipSection.DefaultProvider;
var providerSettings = membershipSection.Providers[defaultProvider];
var connStringName = providerSettings.Parameters["connectionStringName"];
How can I get the value of the attribute cacheRolesInCookie?
Thanks,
I found my problem. I was casting my config section to the wrong type. HEre is what I have done now.