.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Creating users with a role

Posted By:      Posted Date: September 26, 2010    Points: 0   Category :ASP.Net

Hi, i'm programitcally creating user using theSqlMembershipProvider. I am able to create users however now I want to be to assign them to a certain role once they are created.  How do I go about assigning the newly created user to a role? 


CODE to create user, works fine:

 protected void btn_createUser_Click(object sender, EventArgs e)
            MembershipCreateStatus createStatus;

            //create some code here that compares the first password and confirm password

            MembershipUser newUser = Membership.CreateUser(tbox_user.Text, tbox_password.Text, tbox_email.Text, lbl_passQuest.Text, tbox_passwordAnswer.Text, true, out createStatus);

            switch (createStatus)
                case MembershipCreateStatus.Success:
                    lbl_resultsOfCreate.Text = "user Created";

                case MembershipCreateStatus.DuplicateUserName:
                    lbl_resultsOfCreate.Text = "User name already exists";

                case MembershipCreateStatus.DuplicateEmail:
                    lbl_resultsOfCreate.Text = "This email address is already in use";

                case MembershipCreateStatus.InvalidEmail:

View Complete Post

More Related Resource Links

Assigning users when creating a list item in a workflow


I'm using a workflow to assign tasks to users.  When I try to assign the task to a group (set in the workflow designer), the workflow gives me an error.  When I change the assign to property to a single user, the workflow works perfectly.  How do I get the workflow to assign the task to the group?  Or if that's not possible, can I get it to assign it to more than one user?


Creating a gridview to allow editing of current users


I finally got membership and roles setup and seems to be working.

I have setup a page to allow the creation of a user and editing of roles for a user.

I would like to setup a page with a gridview that displays all users and what roles they are assigned. I remember running across someone else that was looking to do the same thing, but cant find it. Not sure if it was in this forum or online somewhere else.

But i found that i can use the  aspnet_Membership_GetAllUsers procedure in my db to get all the users, but how can i add the roles to each person and possibly setup the gridview so that each role they have, is displayed on their row in the gridview

So i would like to see something like this maybe more data displayed depending on the client request.

Username                 Email                 Last Login                          Roles

meofcourse               m

Checking SQL Server User Roles and Creating SQL Server Users using VB.NET

Hello gurus!Firstly I want to apologies if this question is out of place here.. if someone can direct me to the correct forumn great and Thanks!I have a VB.NET application which uses its own Backend Database (MSSQL Server). I need to distribute this application to sites where there will be an existing SQL Server.So I will need to Create the Database on this server. The Application includes methods for building the database on startup if not already connected to one.However the users windows logon may not have the correct permission to connect and create a Database on the Server. I have a DB Setup form in my application which asks for the Servname, Username, Password and Database name. I have catered for Windows Authentication and SQL Server Authentication within the form - the user makes the choice.Assuming they enter a Username and Password for SQL Server Athentication then I will be trying to connect using this user and create the database on the given server. The following is my outline logic:-                                                                  Create db Process                                                                             |                                                                             |                                                               Check Credentials                                                                   / 

Custom Role Provider Not Authenticating Users

I have created a custom role provider that is hard coded to say everyone is in a certain group (code below).  I have edited the webconfig of Central Admin, my Web Front End, and the Claims Service.  I can sucessuflly log in using the asp.net membership provider and configured access to the site by adding the "custom" role to the Owner Group.  With all of the above items setup I can launch visual studio and attach the to IIS process and verify that my custom role provider is being called.  Even with all this setup I cannot get another forms based user to be able to access the site.  The other user is getting a sharepoint access denied issues. Any Ideas?   public class IdBasedRoleProvider : RoleProvider { public const string AllAuthenticatedUsersRoleName = "custom"; public override string ApplicationName { get; set; } public override string[] GetRolesForUser(string username) { return new[] { AllAuthenticatedUsersRoleName }; } public override bool RoleExists(string roleName) { if (roleName == AllAuthenticatedUsersRoleName) return true; else return false; } #region Methods Not Implemented public override string[] GetAllRoles() { throw new NotImplementedException(); } public override bool IsUserInRole(string username, string roleName) { throw new NotImplementedException(); } public override void Ad

Changing a users role with RadioButtons (User is always in single role)

So I have a set of 5 radio buttons corresponding to the roles a user can have on my website.  I have been successfully able to retreive what radio button needs to be checked for the role the user is currently in... string username = Request.QueryString["username"]; // Get Access Levels and populate radio buttons. if (Roles.IsUserInRole(username, "Banned") == true) { RadioButton4.Checked = true; } if (Roles.IsUserInRole(username, "Member") == true) { RadioButton1.Checked = true; } if (Roles.IsUserInRole(username, "FOB_Employee") == true) { RadioButton2.Checked = true; } if (Roles.IsUserInRole(username, "FOB_Administrator") == true) { RadioButton3.Checked = true; } if (Roles.IsUserInRole(username, "Webmaster") == true) { RadioButton5.Checked = true; } My problem is I do not know what to do with the actual procedure of changing the roles based on the new radio button selection.  I have tried many different methods, including using if statements to check if the user is currently in the role, remove him/her from that roll, and then add the user to the newly selected role.  It appears, from my testing, that you can not

Problem with users needing sysadmin server role to connect to db

When we create a new user in SQL Management Studio 2005 and give it just the public server role, it does not allow us to connect to the db. We found that we had to give it the sysadmin server role in order to allow it to connect to the db. We are using a UDL file in order to test connect. It seems that this is true for all users we create in SQL Management Studio 2005. Is there a way where we can change it so that users are not required to have the sysadmin server role in order to connect to a db? We would like it so that if they have at least the public server role, they should be able to connect to the db.

CreateUserWizard creating dupicate user while assigning Role.

protected void CreateUserWizard1_CreatedUser(object sender,  EventArgs e){Roles.AddUserToRole((sender as CreateUserWizard).UserName, "Customers");} CreateUserWizard is creating dupicate user while assigning Role.How can we assign Role without duplicating user record? I've observed ApplicationID for assigning Role is Differenent than Creating New User, so when ever Role assigning comes in, it creates  same user again with new UserID. Is it related to Web.Config in some way? As when I try to create user from "VisualStudio/Website/ASP.net Configuration" even then two users with same usernames are entered in aspnet_users with Different ApplicationID and UserID. One user has Role and another duplicate user is without Role status of IsApproved=1.Please help me to resolve this issue.Thanks!  

creating a role that can read everything?


We have an issue constantly where developers need to see what code is running on our production servers. They also need to script objects out, query system tables, view what logins are, inspect SQL jobs etc. We also need the ability to look at the server configuration too.


It seems that the dba's cant figure out how to create a role that can view object level permissions without granting write access. 

Is there a way a role can be created that has read-only rights to everything? This would save us a ton of time. Currently we have to email the DBA's to send us scripts for things....big PITA


We would like a solution that will work on all servers without modifying the script to create the role


Creating users in Sharepoint Designer 2010

I'm  having trouble creating new users.  I don't see a Manage Users option under Administration section.  I know I'm logged in as an Admin.... can someone please help me out?

Quick way to prevent users from creating sub-sites under their my site?


Probably something very easy that I've just missed... but we want to prevent our users from building loads of sites and such under their my site in SP 2010. Hopefully this will encourage them to use other areas that we are building for them instead of the my site!

Thanks for any input you can provide.

Help creating a user procedure that only shows current users records


Hello all,

MS SQL express 2008, Access 2010, ODBC linked tables, Window NT logins.

Trying to create a user procedure that looks at a master table [DailyReport] For the current system user and only displays records that has their username in the column [FluidControlUsername].

Any help\direction would be much appreciated.


How can we show certain no of dimension only for two different users having different role in a sing



well i might be having a security problem so i just want to know that can we show certain dimension to one user say  (i.e 10dimension for A user and 15 dimension for B user having different user role in a single cube.)

Please any one help me out soon and give some ideas...so that i can solve my issue ,can we solve this issue naa.. :( ..!!!


Anil Maharjan

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Creating your SharePoint Governance Plan

One of the most common questions that I get from prospects as I'm talking to them about the creation of a governance plan and process is what does it look like. In other words, there are materials available which describe what should be in a governance plan but there isn't a ton of guidance on what the process of creating a governance plan and process are.

Enabling Users to Maintain SharePoint Content

When SharePoint is installed as a corporate intranet, there is a considerable amount of effort involved in maintaining the content to keep the site relevant. As we discussed in the first few parts of this series, SharePoint has many built-in features to reduce the burden on the site administrator.

Some areas of the site usually contain less-dynamic information. Internal memos and corporate policies are common examples of this information. One option for this information is to post these documents in a document library. Documents in a library are often stored in a few different formats: Word, Acrobat (PDF), or HTML. Each of these formats has its drawbacks.

Creating Paging for a Repeater Control

A common question is "How do I implement paging within a Repeater?" Although the beauty of the Repeater control is its flexibility, you're on your own for building most functions. ASP.NET 2.0 has included some new controls that provide paging, as does the DataGrid in ASP.NET 1.1. However, this tip shows you how to roll your own paging for a simple data viewer.

Creating an AJAX Repeater in ASP.NET MVC

The "TaskList" is a tried an true example of the most basic thing that you can do in any framework. Unfortunately, I had some problems finding a really good example of all the steps necessary to get a task list to work in ASP.NET MVC 1.0.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend