CS does not have a special moderator concept. It uses a role-based authorization mechanism. We can use this mechanism to implement the moderator function.
For example, I have a section named "irrigation Park". To implement the functions of the Moderator, follow these steps:
1. add a role to act as the moderator of this forum. The role name is "irrigation happy administrator" (here the role name cannot be written at will and must be standardized and will be used later ).
2. Modify the default permissions of this role to make it the same as the permissions of "Everyone. This is because all permissions of the newly created role are restricted.
3. Add the "irrigation Park administrator" role to the "irrigation Park administrator" permission ing list and modify its permissions to manage this forum.
4. If I want the user "AA" to become the moderator, I will add the role "irrigation Park administrator" to "AA ".
This is the procedure for setting a user as the administrator.
Next let's take a look at how to display the moderator list in the Forum list. For more information, see niutou.com.
To implement this function, we need to perform the following steps:
1. Compile the moderator display control (ForumManagersView );
2. Modify the Resource. xml file and add the required string resources;
3. Modify the View-ForumGroupView.ascx control to display the moderator control;
1.Compile the moderator display control (ForumManagersView)
My code is as follows: using System;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Using CommunityServer. Controls;
Using CommunityServer. Components;
Namespace Newtor. CS. Forums. Controls
{
/// <Summary>
/// Summary of ForumManagerView.
/// </Summary>
Public class ForumManagersView: PlaceHolder
{
Public ForumManagersView ()
{
}
Protected override void OnInit (EventArgs e)
{
This. PreRender + = new EventHandler (ForumManagersView_PreRender );
Base. OnInit (e );
}
# Region ForumName attributes
Private string forumName;
/// <Summary>
///
/// </Summary>
Public string ForumName
{
Get
{
Return forumName;
}
Set
{
ForumName = value;
}
}
# Endregion
Public void BindData ()
{
System. Guid roleID;
Try
{
Role role = Roles. GetRole (this. ForumName + ResourceManager. GetString ("ForumManagersView_RoleName_Postfix "));
RoleID = role. RoleID;
}
Catch (CSException e)
{
If (e. ExceptionType = CSExceptionType. RoleNotFound)
Return;
Else
Throw e;
}
UserSet users = Roles. UsersInRole (0, 10, SortUsersBy. LastActiveDate, SortOrder. Descending, roleID );
If (! Users. HasResults) return;
HtmlGenericControl div = new HtmlGenericControl ("div ");
Div. Controls. Clear ();
Div. Controls. Add (new LiteralControl (ResourceManager. GetString ("ForumManagersView_Prefix ")));
Foreach (User user in users. Users)
{
HyperLink userLink = new HyperLink ();
UserLink. NavigateUrl = Globals. GetSiteUrls (). UserProfile (user. UserID );
UserLink. Text = user. Username;
Div. Controls. Add (userLink );
Div. Controls. Add (new LiteralControl (ResourceManager. GetString ("ForumManagersView_ManagersList_Seperator ")));
}
If (div. Controls. Count> 2)
Div. Controls. RemoveAt (div. Controls. Count-1 );
This. Controls. Clear ();
This. Controls. Add (div );
}
Private void ForumManagersView_PreRender (object sender, EventArgs e)
{
BindData ();
}
}
}
The code is very simple and I will not talk about it here. You can change the display mode of the moderator list based on your needs. Here I use a div for horizontal display.
2.Modify the Resource. xml file and add the required string resources.: <Resource name = "ForumManagersView_Prefix"> Moderator: </resource>
<Resource name = "ForumManagersView_RoleName_Postfix"> administrator </resource>
<Resource name = "ForumManagersView_ManagersList_Seperator" >,</resource>
Here, the suffix of the role name is used, which is why the name of the role that acts as the Moderator cannot be obtained at will. Of course, you can change the suffix as needed, or use a more complex expression, but this is not necessary.
3.Modify the View-ForumGroupView.ascx control to display the moderator Control
Here we need to add more information for ourselves. I don't need to talk about the specific method. I put the moderator list on the Forum description. Note that you must set the ForumManagersView parameter for the control. Otherwise, the role cannot be found.