How to get all roles/tasks/operations for one user

Topics: General Topic
May 13, 2012 at 1:50 AM

Hi Andrea,

I am trying to pass in a username and get all its roles or tasks or operations that he is allowed to perform.

I have been using the following but no its not working:

NetSqlAzMan.Providers.NetSqlAzManRoleProvider provider = new NetSqlAzMan.Providers.NetSqlAzManRoleProvider();

string []roles = provider.GetRolesForUser(user);

It seems that the "provider" is always null.

Here is the web.config setup:

    <add name="NetSqlAzManRoleProvider" connectionString="Data Source=MYSERVER;Initial Catalog=NetSqlAzManStorage;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
  </connectionStrings>

  <system.web>
    <identity impersonate="false"/>
    <authentication mode="Windows"/>
    <authorization>
      <deny users="?"/>
      <allow users="*"/>
    </authorization>
    <compilation debug="true" targetFramework="4.0" />

    <roleManager defaultProvider="NetSqlAzManRoleProvider" enabled="true" cacheRolesInCookie="false" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
      <providers>
        <clear/>
        <add
        name="NetSqlAzManRoleProvider"
        type="NetSqlAzMan.Providers.NetSqlAzManRoleProvider"
        connectionStringName="NetSqlAzManRoleProvider" storeName="My Store" applicationName="My Application" userLookupType="LDAP" defaultDomain="" UseWCFCacheService="False" />
      </providers>
    </roleManager>
Coordinator
May 14, 2012 at 6:24 AM

Try this:

NetSqlAzMan.Providers.NetSqlAzManRoleProvider provider = ((NetSqlAzManRoleProvider)Roles.Provider);

__________________________________
Andrea Ferendeles
NetSqlAzMan Project Coordinator
E-mail aferende@hotmail.com Web http://netsqlazman.codeplex.com

Developer
May 14, 2012 at 6:20 PM

The purpose of the Provider pattern is to achieve Transparency. You don't need initialize the provider, ASP.Net will do it.

Just call  

System.Web.Security.Roles.GetRolesForUser()

No initialization needed. And you have a list of functions to use.

 

Richard

May 17, 2012 at 1:10 PM

Thanks.

Both answers work just fine.