locked
Custom Membership role provider is intializing to soon RRS feed

  • Question

  • User-1121540557 posted

    Hi,

    I've written a custom role provider, but it is initializing to soon..

    When load the webpage the initalization on the role provider is first to be started..problem is that i need start it after the user has loged in.

        <roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="true">

          <providers>

            <clear/>

            <add name="CustomRoleProvider"    type="namespace.oleProvider" connectionStringName="ConnectionStringName"    applicationName="someApp"/>            

          </providers>

        </roleManager>

    if I clear cacheRolesInCookie="true" then it won't initialize any more

    Anybody knows how to solve this?

    Best regards,

    Mark

    Wednesday, April 30, 2014 4:45 PM

All replies

  • User1140095199 posted

    Hi,

      Greetings!

    I've written a custom role provider, but it is initializing to soon..

    Could you elaborate more on what you mean by "initializing too soon".

    The way I look to it is cacheRolesInCookie is set to true .

    <roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="true">

    When you set it to true in the Web.config file, role information for each user is stored in a cookie. When role management checks to see whether a user is in a particular role, the roles cookie is checked before the role provider is called to check the list of roles at the data source. The cookie is dynamically updated to cache the most recently validated role names.

    So , it might be the case it is getting the values from the Cookie. Hence, you are getting the impression that it is getting initialized too soon.

    For more reference - http://msdn.microsoft.com/en-us/library/system.web.security.roles.cacherolesincookie(v=vs.110).aspx

    Do get back with more information if I am missing a point here.

    Hope it helps!

    Best Regards!

    Friday, May 2, 2014 12:04 AM
  • User-1121540557 posted

    Hi Sam,

    Ok the role provider is already initializing when i load the form for the first time..bud the problem is when the user logs-in the membership provider is initialized and the role provider not...In other words, the data from the .config file (connection string, application name etc.) is only loaded when the membership provider is initialized...but not in the role provider and al the data in the previous initialization(when the web form is loaded for the first time) is destroyed...

    Ofcourse I can use session variables or cookies but why do that if I can set the initalization in the roleprovider on time when the user logs-in?

    Even so I don`t need the rolemanager to be enabled, because I write my own authorization model...Bud I need it to be initialized on time(After login).

    Hope you know how to solve this or a good work arround..

    Best regards,

    Mark

    Friday, May 2, 2014 11:35 AM