gymcode
gymcode

Reputation: 4633

Bringing ASP.NET Website Admin Tool functionality to webpage

I am using VS2005 .NET 2.0 C#.

I am currently managing my user roles by the build in ASP.NET Web Site Administration Tool, managing users etc, as well as using ActiveDirectory authentication

I have 2 questions.


Firstly, is there any sample code which I can refer to on the web in order to implement the role editing of the ASP.NET Website Admin Tool onto my webpage? The GUI need not be there, I only require the username and the role checkboxes on my webpage.

enter image description here Working code examples will be appreciated


Secondly, I have been receiving an error when I tried to create a new user after I have changed my authentication from Web to Windows, which uses ActiveDirectory. Below is the error:

enter image description here

Is it because AD does not allow creating of new users or is it because the account I provided in my connectionUsername and connectionPassword in the web.config does not have sufficient privilege?


EDIT:

For my first question, I have a button which loads the user role from a database.

enter image description here

Below is the method:

protected void loadUser_Click(object sender, EventArgs e)
{
    AdminCb.Checked = false;
    UserCb.Checked = false;
    SqlConnection conn = new SqlConnection("Data Source=TP;Initial Catalog=MP;User ID=user;Password=password");
    string sql = "SELECT [User Type] FROM [UserRoles] where [Name]=@Name";
    SqlCommand cmd = new SqlCommand(sql, conn);
    cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50).Value = UserNameList.Text;
    conn.Open();
    Object result = cmd.ExecuteScalar();
    conn.Close();

    if (result != null)
    {
        string usertype = result.ToString();
        if (usertype == "Super User")
        {
            AdminCb.Checked = true;
        }
        if (usertype == "Normal User")
        {
            UserCb.Checked = true;
        }

    }
}

Is it possible for me to retrieve the list of users from ActiveDirectory and implement it similar to my method above?

Upvotes: 4

Views: 1238

Answers (1)

user596075
user596075

Reputation:

As for your first question, the Website Admin Tool is simply a web interface that sits on top of the Membership API. In other words, if you click something like "add a new role" on the Web Admin Tool, you're basically calling Roles.CreateRole().

How you want to design your web interface is up to you. But to utilize the complete functionality of the Website Admin Tool, you need to implement many of the classes in System.Web.Security namespace.

Upvotes: 3

Related Questions