You are here:   Forum
  |  Login

Programmer Forum

Minimize
 
  Programmer Forum  Discussions  Asp.net  Asp.net Membership Roles.CreateRole does not work error creating role
Disabled Previous
 
Next Next
New Post 1/21/2010 10:49 PM
Resolved
  Software Programming
10 posts
No Ranking


Asp.net Membership Roles.CreateRole does not work error creating role 

Problem: Asp.net Membership Roles.CreateRole does not work error creating role.

When trying to get Asp.net Membership Roles.CreateRole(rolename) function to work you get an exception error. If you go to the trouble to look up the exception you see this.

System.Configuration.Provider.ProviderException - Role management is not enabled.

The Role class is documented here.
http://msdn.microsoft.com/en-us/library/system.web.security.roles.aspx

Solution:

This error tells you that you do not have the role manager enabled in your web.config file.

If none of the other Role methods work, you probably do need to enable the role manager class. Here is the code for your web.config file.

<roleManager cacheRolesInCookie="true" enabled="true">
  <providers>
    <
clear/>
    <
add applicationName="/" connectionStringName="databaseConnectionString"
      
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
  </
providers>
</
roleManager>

But what if you can use the other role manager methods and your web.config has role manager enabled?

If you Visual Studio, select Website from the top menu and then go to Asp.Net Configuration. Go to the Security page and try to add a new role. See if you get this error message.

Cannot insert the value NULL into column 'RoleId', table 'gib_database.dbo.aspnet_Roles'; column does not allow nulls. INSERT fails. The statement has been terminated.

If you do, that means the RoleId default value in your database has been removed. Have no idea how that happens. The RoleId field in the dbo.aspnet_Roles table does not allow nulls (a good thing). It should be automatically set to a new uniqueid.

You will need to go into your database using Microsoft Sql Server Management Studio. Find the dbo.aspnet_Roles table in your database. Right click the table and select Design.

Left click the RoleId field. In the properties at the bottom, find Default Value or Binding. This is probably blank. You need to set it to:

newid()

Save your changes by closing the window (click the x in the upper right of the window), exit Sql Server Management Studio, and try again.

There is something called a NEWSEQUENTIALID(), which gives better performance, but does not seem to work as a default value in Sql Server Express 2008.

 
Disabled Previous
 
Next Next
  Programmer Forum  Discussions  Asp.net  Asp.net Membership Roles.CreateRole does not work error creating role

Programmer Newsletter

Minimize

Subscribe to the Internet Handholding newsletter



Reccomend Programmer.bz

Minimize

Share/Bookmark Bookmark and Share