Changing Default Role

Topics: Help, Request
Jun 10, 2007 at 4:02 PM
What do I change to allow new registerations to become administrators instead of guests - immediately?

Jun 10, 2007 at 8:00 PM

dpr00 wrote:
What do I change to allow new registerations to become administrators instead of guests - immediately?


Hi. The best way to do this is in the code. On line 16 of the member/register.aspx page, I would put in the following code:

Roles.AddUserToRole(user.UserName.ToString(), "Administrators")

user was declared earlier in that try statement and you can just pull the username and assign it to the role "Administrators" after the user clicks finish.

You might look at the ramifications of this, though. It might not be best to assign all users to "Adminisitrators" because of the actions an administrator can take such as deleting users. Think about it before you do it.
Jun 10, 2007 at 11:38 PM
I was wondering how to do this because I can't make myself the administrator - every time I try to upload the schema.sql I get the following error:

Msg 15007, Level 16, State 1, Line 42
'zowens' is not a valid login or you do not have permission.
Msg 15151, Level 16, State 1, Line 1
Cannot find the user 'zowens', because it does not exist or you do not have permission.
Msg 2759, Level 16, State 0, Line 1
CREATE SCHEMA failed due to previous errors.

I thought this might be a temporary solution to become administrator. However, it didn't work. Thanks for your help. Do you have any other suggestions? How do I fix these errors?
Jun 11, 2007 at 1:59 PM
So you aren't able to upload the scheme? Can you regenerate your database? I would use the SQL Publishing Wizard. Sorry about that... I'm not quite sure why the scripts haven't been working... they were generated using SQL SMO.
Jun 11, 2007 at 7:24 PM
I used the wizard however I dont think it work - it seemed to delete many of my tables and gave me this new error: The database does not appear to contain WebContent table, this is a feature of the extended ClubSite, please ensure you have run WebContent.SQL against the database. It also says asp_netroles (table) does not exist.

Still cannot become admin and now have these errors.

Any help is appreciated!
Jun 12, 2007 at 12:38 AM
These errors seemed to work themselves out - because all tables are back now:

when I submitt this (in Godaddy's Query Analyzer to make myself admin):
SELECT RoleId FROM aspnet_Roles WHERE RoleName='Administrators'
I get:
0 record(s) affected. (instead of a set of numbers)

This is my only problem. What is wrong?
Jun 12, 2007 at 11:59 PM
New update: I now cannot login.

Any help is appreciated!
Thanks in advance.
Jun 17, 2007 at 1:57 AM
Edited Jun 17, 2007 at 1:58 AM
It sounds to me like you don't want to make every user that joins an administrator, you just want to make yourself an administrator, and you can't figure out how to do that.

You have a couple issues that I can see:
1. Your select RoleId from aspnet_Roles should have returned the GUID that is assigned to the Administrators role. Since it didn't, you probably wiped out the data from the table.
2. You probably should wipe your database out, and restart it from scratch. That will be the only way that you can be sure that the roles and everything is setup correctly.

After that is completed, I would probably just put a temp ASPX file on the site. Something like this:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="temp.aspx.vb" Inherits="temp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>

Partial Class temp
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Roles.AddUserToRole(TextBox1.Text, "Administrators")
End Sub
End Class

load this page AFTER you create your login. Then load this page, put your username in the textbox and click the button. Your username should then be in the Administrators role.

After you have one Administrator, delete these pages from the site.