Both InstantForum.NET & InstantKB.NET use our InstantASP.Common framework to manage core user information & user role relationships. Roles (also known as member groups) are used within both InstantForum.NET & InstantKB.NET to control the content accessible to your end users.
If your creating users within our database using our API you may wish to also automatically associate specific forum or knowledgebase roles with users you create via our API.
The code below shows how to add and delete user & role relationships within a separate ASP.MET web application. In the example we are using "1" as the user identity. This identity could be replaced with any genuine ser identity from the "InstantASP_Users" database table.
Before using our API please ensure you've read the following articles "Using the InstantForum.NET API" or "Using the InstantKB.NET API"..
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' userid from InstantASP_Users
Dim intUserID As Int32 = 1
' get admin role
Dim Role As InstantASP.Common.Components.UserRole = _
InstantASP.Common.Business.Roles.SelectRole( _
InstantASP.Common.Enumerations.EnumRequiredRoles.Administrator)
' this call will associate the supplied user identity with administrator role
InstantASP.Common.Business.UserRoles.AddUserRole(intUserID, Role.RoleID)
' this call will delete the user and administrator role relationship
InstantASP.Common.Business.UserRoles.DeleteUserRole(intUserID, Role.RoleID)
' this call will delete all roles associated to the supplied user identity
InstantASP.Common.Business.UserRoles.DeleteUserRoles(intUserID)
End Sub
The code below will add a custom role to the InstantASP_Roles table. You can pass in a number of arguments to the InsertUpdateRole method. The RoleID argument if 0 will always add a new role. If you pass in an existing RoleID the method will attempt to update the existing role.
Dim intRoleID As Int32 = 0
Dim strRoleName As String = "My Custom Role"
Dim strOpenMarkUp As String = "<strong>"
Dim strCloseMarkUp As String = "</strong>"
Dim bolIsAdminRole As Boolean = False
Dim bolIsModeratorRole As Boolean = False
' add role
Dim Role As InstantASP.Common.Components.UserRole = _
InstantASP.Common.Business.Roles.InsertUpdateRole( _
intRoleID, strRoleName, True, strOpenMarkUp, strCloseMarkUp, _
bolIsModeratorRole, bolIsModeratorRole)
This mehtod returns a InstantASP.Common.Components.UserRole object representing your new role. You should see your new role added to the InstantASP_Roles table.
To associate specific roles with users within InstantForum.NET or InstantKB.NET you should use the following API…
InstantASP.Common.Business.UserRoles.AddUserRole(intUserID, intRoleID)
Where intUserID is a valid UserID from the InstantASP_Users table and intRoleID is a valid RoleID from the InstantASP_Roles table.
This will add a single role relationship to the InstantASP_UserRoles table.
The method below will delete a single role relationship for a specific user.
InstantASP.Common.Business.UserRoles.DeleteUserRole(intUserID, intRoleID)
Where intUserID is a valid UserID from the InstantASP_Users table and intRoleID is a valid RoleID from the InstantASP_Roles table.
This will delete a single role relationship from the InstantASP_UserRoles table.
The method below will delete all roles associated with a specific user.
InstantASP.Common.Business.UserRoles.DeleteUserRoles(intUserID)
Where intUserID is a valid UserID from the InstantASP_Users table. This will delete all role relationships for a single user.