Hey all,
Below is my aspx.vb code and I am stumped as to why when I enter a user name then select a role the user is added to a role, but not the one I select in my dropdown.
The user is always added to the first role in the list in the dropdown not the role I selected. As well the RemoveUserFromRole doesn't work, I have to go into my DB and remove them manually.
Imports
System.Web.SecurityPartial
Class AddRemoveUserRoles Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadDataBind()
End Sub Public Sub AddUserToRole_Click(ByVal sender As Object, ByVal e As EventArgs) Dim username As String = UsernameTextBox.Text.ToString Dim roleName As String = RoleDropDownList.SelectedItem.Value.ToStringRoles.AddUserToRole(username, roleName)
End Sub Public Sub RemoveUserFromRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim username As String = UsernameTextBox.Text.ToString Dim roleName As String = RoleDropDownList.SelectedItem.Value.ToStringRoles.RemoveUserFromRole(username, roleName)
End Sub Public Overrides Sub DataBind()RoleList.DataSource = Roles.GetAllRoles()
RoleList.DataBind()
End SubEnd
Class
www.someguy.ca rantings from some Canadian guy
Follow me on twitter as well twitter.com/SomeCanadianGuy
![]() |
0 |
![]() |
I've been trying many different code styles but still to no avail, I am sure it likely just something small I am over looking...
www.someguy.ca rantings from some Canadian guy
Follow me on twitter as well twitter.com/SomeCanadianGuy
![]() |
0 |
![]() |
No ideas as to why this is not working?
www.someguy.ca rantings from some Canadian guy
Follow me on twitter as well twitter.com/SomeCanadianGuy
![]() |
0 |
![]() |
do some debugging
add a break point on this line
Roles.AddUserToRole(username, roleName)
and move the mouse over the roleName
and see what is the roleName value that passed to the AddUserToRole function(i think it will be the roleId Not RoleName)
because the RoleDropDownList.SelectedItem.Value return the RoleId
and instead of this
Dim roleName As String = RoleDropDownList.SelectedItem.Value.ToString
write this
Dim roleName As String = RoleDropDownList.SelectedItem.Text
Regards,
Anas Ghanem.
Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!
![]() |
0 |
![]() |
But I am adding the information to the UserinRoles Table, the table colums are UserId and RoleId. Both of wich are uniqueidentifiers so I need the value of the text box inserted into the table not text itself.
Oh wait is that maybe it, roelName as String is not correct. Should roleName not be a new uniqueidentifier?
Anyway I will try what you sugested, thank you.
www.someguy.ca rantings from some Canadian guy
Follow me on twitter as well twitter.com/SomeCanadianGuy
![]() |
0 |
![]() |
Sorry I ment a new guid
www.someguy.ca rantings from some Canadian guy
Follow me on twitter as well twitter.com/SomeCanadianGuy
![]() |
0 |
![]() |
Maybe I am tired or something but I am really getting frustraited with this.
I have followed so many online tutorials and step by step examples from different source and everyone says this is easy, yet I still get errors.
I am working along with a video from that Scott guy from Vertigo Software on the Membership and Roles. Here is his code that works fine for him on the video
Public Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)DropDownList1.DataSource = Roles.GetAllRoles()
DropDownList1.DataBind()
End Sub Public Sub DeactivateStep(ByVal sender As Object, ByVal e As System.EventArgs)Roles.AddUsersToRole(User.Identity.Name, DropDownList1.SelectedValue)
End SubBut when I do it I get the "User.Identity.Name" Error Value of type 'String' cannot be converted to '1-dimensional array of String'.
What the heck am I missing...lol....I just added a step to the add new user wizard to select a role that I have already created.....
www.someguy.ca rantings from some Canadian guy
Follow me on twitter as well twitter.com/SomeCanadianGuy
![]() |
0 |
![]() |
Rivelyn:
Public Sub DeactivateStep(ByVal sender As Object, ByVal e As System.EventArgs)Roles.AddUsersToRole(User.Identity.Name, DropDownList1.SelectedValue)
End SubBut when I do it I get the "User.Identity.Name" Error Value of type 'String' cannot be converted to '1-dimensional array of String'.
What the heck am I missing...lol....I just added a step to the add new user wizard to select a role that I have already created.....
man You are using the wrong Function
Use AddUserToRole Not AddUsersToRoleand also this is a goooooood example for your case from microsoftim Very sure that it will help youhttp://msdn2.microsoft.com/en-us/library/system.web.security.roles.addusertorole.aspxand this is a list of the available Role functions For Users .. Use The Bold OnePublic method Static AddUsersToRole Adds the specified users to the specified role. Public method Static AddUsersToRoles Adds the specified users to the specified roles. Public method Static AddUserToRole Adds the specified user to the specified role. Public method Static AddUserToRoles Adds the specified user to the specified roles.Reference : MSDN ..good luck
Regards,
Anas Ghanem.
Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!
![]() |
0 |
![]() |
OMG!.....I want to curl up into a ball and cry from embarrassment....I can't believe I actually over looked that......
Thank you very much for your observation anas....
You’re my hero!!!!!
www.someguy.ca rantings from some Canadian guy
Follow me on twitter as well twitter.com/SomeCanadianGuy
![]() |
0 |
![]() |
if you solve your problem
and i hope that ... i want you just to mark the thread as answered ...
thanx
Regards,
Anas Ghanem.
Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!
![]() |
0 |
![]() |