Content is still under development. For additional information please consult our community forums, knowledgebase or open a support ticket.

Contents

Documentation

Working with the Instantforum.NET User Object


The code below shows how to populate the InstantForum.NET user object from a web site using ASP.NET forms authentication. It also demonstrates how to get the roles (known as member groups within InstantForum.NET) associated with a forum user account.

Public Class _Default
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' simple check to see if authenticated user belongs to the administrator role
        If System.Web.HttpContext.Current.User.IsInRole("Administrators") Then
            System.Web.HttpContext.Current.Response.Write("You are an administrator!
") Else System.Web.HttpContext.Current.Response.Write("You are NOT an administrator!
") End If ' simple check to see if authenticated user belongs to the moderator role If System.Web.HttpContext.Current.User.IsInRole( _ InstantASP.Common.Business.Roles.SelectRole( _ InstantASP.Common.Enumerations.EnumRequiredRoles.Moderator).RoleName) Then System.Web.HttpContext.Current.Response.Write("You are a moderator!
") Else System.Web.HttpContext.Current.Response.Write("You are NOT a moderator!
") End If ' local user object Dim User As InstantASP.InstantForum.Components.User ' list all roles associated with a user ' are we authenticated? If System.Web.HttpContext.Current.Request.IsAuthenticated Then ' render text System.Web.HttpContext.Current.Response.Write("You are associated to the following roles:
") ' if so attempt to create forum user object from generic principal object User = InstantASP.InstantForum.Business.User.SelectUser( _ System.Web.HttpContext.Current.User.Identity) ' loop through roles associated with user rendering to screen For Each Role As InstantASP.Common.Components.UserRole In User.UserRolesCollection System.Web.HttpContext.Current.Response.Write( _ Role.RoleID.ToString() + ", " + Role.RoleName + "
") Next End If ' determine the users primary role within InstantForum.NET ' are we authenticated? If System.Web.HttpContext.Current.Request.IsAuthenticated Then ' if so attempt to create forum user object from generic principal object User = InstantASP.InstantForum.Business.User.SelectUser( _ System.Web.HttpContext.Current.User.Identity) ' render primary role System.Web.HttpContext.Current.Response.Write("You're primary role is: ") System.Web.HttpContext.Current.Response.Write( _ User.UserRolesCollection.PrimaryRole.RoleName) End If End Sub End Class




© 2011 InstantASP Ltd. All Rights Reserved. Powered by InstantKB.NET 2011-1