Question

I'm developing an ASP.NET MVC3 website and I'm using the Microsoft ASP.NET Universal Providers. Web.config :

<connectionStrings>
<add name="MyContext" connectionString="data source=tcp:***.database.windows.net,1433;Initial Catalog=***;User Id=***;Password=***;Trusted_Connection=False;Encrypt=True;Connection Timeout=30" providerName="System.Data.SqlClient" />
</connectionStrings>
...
<roleManager defaultProvider="DefaultRoleProvider" enabled="true">
  <providers>
    <clear />
    <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider" connectionStringName="MyContext" applicationName="/" />
  </providers>
</roleManager>

The connectionStrings is ok in Azure. Aspnet tables and storedprocedures I added by using the query script. Data in tables added by migrations. I checked it in management portal. I can get profile membership and profile data, but the the code below returns empty list.

var userName = User.Identity.Name;
var userRoles = Roles.GetRolesForUser(userName).ToList();

userName is correct and table aspnet_UsersInRoles contains correct data too. There is no exceptions on page. Why the userRoles is empty?

Was it helpful?

Solution

I fix this problem by creating the custom provider, which is inherited from SqlRoleProvider.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top