最佳解决方案:实现 SharePoint 网站分类解决方案

优采云 发布时间: 2022-09-24 05:11

  最佳解决方案:实现 SharePoint 网站分类解决方案

  实施 SharePoint 网站分类解决方案

  注意事项

  对于 SharePoint Online 网站 分类,请参阅以下 文章:SharePoint“现代”网站 分类。

  即使管理良好,SharePoint 网站 也可能激增并失控。 网站 是按需创建的,但很少被删除。未使用的 网站 会增加搜索爬网的负担,并且搜索会产生过时且不相关的结果。通过网站分类,可以识别和保留敏感数据。

  本文向您展示如何使用 Core.SiteClassification 示例实施 网站分类解决方案,以及如何使用 SharePoint 网站策略强制删除。该解决方案可以集成到现有的网站设置解决方案中,以更好地管理您的网站。

  准备

  要开始使用,请从 GitHub 上的 Office 365 开发人员模式和实践项目下载 Core.SiteClassification 示例。

  注意事项

  本文中的代码按原样提供,不提供任何明示或暗示的保证,包括对特定用途的适用性、适销性或不侵权的暗示保证。

  定义和设置网站策略

  首先,您需要定义和设置将在您的所有 网站 集中可用的 网站 策略。 Core.SiteClassification 示例适用于 SharePoint Online MT,但也可用于 SharePoint Online Private 或 SharePoint On-Premises。 网站在内容类型中心(在 SharePoint Online MT 中的 [tenantname]/sites/contentTypeHub 中)设置策略。

  要设置 网站策略,请转至设置 > 网站设置管理 > 网站策略 > 创建。将显示新网站策略页面。有关 网站策略选项的详细信息,请参阅 网站SharePoint Server 中的策略概述。

  在新网站策略页面上,在字段中输入以下信息:

  对于名称 MBI 和 LBI,再重复这些步骤两次。对删除或保留策略使用不同的设置。完成后,您可以发布新政策。

  插入自定义操作

  您可以将 网站 分类的自定义操作插入“设置”页面和 SharePoint 齿轮图标。此操作仅适用于具有 ManageWeb 权限的用户。有关详细信息,请参阅默认自定义操作位置和 ID。

  ///

/// Adds a custom Action to a Site Collection.

///

/// The Authenticated client context.

/// The provider-hosted URL for the application

static void AddCustomAction(ClientContext ctx, string hostUrl)

{

var _web = ctx.Web;

ctx.Load(_web);

ctx.ExecuteQuery();

// You only want the action to show up if you have manage web permissions.

BasePermissions _manageWebPermission = new BasePermissions();

_manageWebPermission.Set(PermissionKind.ManageWeb);

CustomActionEntity _entity = new CustomActionEntity()

{

Group = "SiteTasks",

Location = "Microsoft.SharePoint.SiteSettings",

Title = "Site Classification",

Sequence = 1000,

Url = string.Format(hostUrl, ctx.Url),

Rights = _manageWebPermission,

};

CustomActionEntity _siteActionSC = new CustomActionEntity()

{

Group = "SiteActions",

Location = "Microsoft.SharePoint.StandardMenu",

Title = "Site Classification",

Sequence = 1000,

Url = string.Format(hostUrl, ctx.Url),

Rights = _manageWebPermission

};

_web.AddCustomAction(_entity);

_web.AddCustomAction(_siteActionSC);

}

  自定义网站类别

  您可以使用编辑网站信息页面选择以下特定分类选项:

  Audience Scope 和 网站Category 都是可搜索的,并且在爬网发生后都具有与之关联的托管属性。然后,您可以使用这些属性通过 网站 集中的自定义隐藏列表搜索特定类型的 网站。此列表在 SiteManagerImpl 类的 Core.SiteClassification.Common 项目中实现。

  private void CreateSiteClassificationList(ClientContext ctx)

{

var _newList = new ListCreationInformation()

{

Title = SiteClassificationList.SiteClassificationListTitle,

Description = SiteClassificationList.SiteClassificationDesc,

TemplateType = (int)ListTemplateType.GenericList,

Url = SiteClassificationList.SiteClassificationUrl,

QuickLaunchOption = QuickLaunchOptions.Off

};

if(!ctx.Web.ContentTypeExistsById(SiteClassificationContentType.SITEINFORMATION_CT_ID))

{

// Content type.

<p>

ContentType _contentType = ctx.Web.CreateContentType(SiteClassificationContentType.SITEINFORMATION_CT_NAME,

SiteClassificationContentType.SITEINFORMATION_CT_DESC,

SiteClassificationContentType.SITEINFORMATION_CT_ID,

SiteClassificationContentType.SITEINFORMATION_CT_GROUP);

FieldLink _titleFieldLink = _contentType.FieldLinks.GetById(new Guid("fa564e0f-0c70-4ab9-b863-0177e6ddd247"));

titleFieldLink.Required = false;

contentType.Update(false);

// Key field.

ctx.Web.CreateField(SiteClassificationFields.FLD_KEY_ID,

SiteClassificationFields.FLD_KEY_INTERNAL_NAME,

FieldType.Text,

SiteClassificationFields.FLD_KEY_DISPLAY_NAME,

SiteClassificationFields.FIELDS_GROUPNAME);

// Value field.

ctx.Web.CreateField(SiteClassificationFields.FLD_VALUE_ID,

SiteClassificationFields.FLD_VALUE_INTERNAL_NAME,

FieldType.Text,

SiteClassificationFields.FLD_VALUE_DISPLAY_NAME,

SiteClassificationFields.FIELDS_GROUPNAME);

// Add Key field to content type.

ctx.Web.AddFieldToContentTypeById(SiteClassificationContentType.SITEINFORMATION_CT_ID,

SiteClassificationFields.FLD_KEY_ID.ToString(),

true);

// Add Value field to content type.

ctx.Web.AddFieldToContentTypeById(SiteClassificationContentType.SITEINFORMATION_CT_ID,

SiteClassificationFields.FLD_VALUE_ID.ToString(),

true);

}

var _list = ctx.Web.Lists.Add(_newList);

list.Hidden = true;

list.ContentTypesEnabled = true;

list.Update();

ctx.Web.AddContentTypeToListById(SiteClassificationList.SiteClassificationListTitle,

SiteClassificationContentType.SITEINFORMATION_CT_ID, true);

this.CreateCustomPropertiesInList(_list);

ctx.ExecuteQuery();

this.RemoveFromQuickLaunch(ctx, SiteClassificationList.SiteClassificationListTitle);

}

</p>

  默认情况下,当您创建现成列表或使用 CSOM 创建列表时,该列表将在“最近”菜单中可用。但该列表需要隐藏。以下代码将从“最近”菜单中删除该项目。

  private void RemoveFromQuickLaunch(ClientContext ctx, string listName)

{

Site _site = ctx.Site;

Web _web = _site.RootWeb;

ctx.Load(_web, x => x.Navigation, x => x.Navigation.QuickLaunch);

ctx.ExecuteQuery();

var _vNode = from NavigationNode _navNode in _web.Navigation.QuickLaunch

where _navNode.Title == "Recent"

select _navNode;

NavigationNode _nNode = _vNode.First();

ctx.Load(_nNode.Children);

ctx.ExecuteQuery();

var vcNode = from NavigationNode cn in _nNode.Children

where cn.Title == listName

select cn;

NavigationNode _cNode = vcNode.First();

_cNode.DeleteObject();

ctx.ExecuteQuery();

}

  Core.SiteClassification 示例提供了允许 网站 管理员或有权删除新列表的人的可能性。访问此页面时,将再次创建列表,但示例不会重置属性。您可以通过扩展示例并将列表上的权限修改为只能由 网站set 管理员访问来避免这种情况。或者,您可以使用 Core.SiteEnumeration PnP 示例检查列表并相应地通知 网站管理员。

  列表验证检查也可以在 SiteManagerImpl 类的 Initialize 成员中实现。

  

  internal void Initialize(ClientContext ctx)

{

try {

var _web = ctx.Web;

var lists = _web.Lists;

ctx.Load(_web);

ctx.Load(lists, lc => lc.Where(l => l.Title == SiteClassificationList.SiteClassificationListTitle));

ctx.ExecuteQuery();

if (lists.Count == 0) {

this.CreateSiteClassificationList(ctx);

}

}

catch(Exception _ex)

{

}

}

}

  注意事项

  有关详细信息,请参阅安装 SharePoint 加载项后在主机 Web 中创建列表并将其从现有配置文件列表中删除。

  将类别指示器添加到 网站页面

  您可以将指标添加到您的 网站 页面以显示它们的类别。 Core.SiteClassification 示例展示了如何在“网站Title”旁边嵌入显示通知的图像。在早期版本的 SharePoint 中,这是通过服务器端委派控件完成的。尽管您可以使用 JavaScript 的自定义母版页,但此示例使用嵌入式 JavaScript 模式。当您在“编辑网站信息”页面中更改“网站策略”时,这将更改 网站 指示符,以便为每个 网站 分类选项背景颜色使用不同的颜色显示一个小框。

  Core.SiteClassificationWeb 项目、脚本和classifier.js 中定义了以下方法。图片存储在 Microsoft Azure 网站 中。您需要更改硬编码的 URL 以匹配您的环境。

  function setClassifier() {

if (!classified)

{

var clientContext = SP.ClientContext.get_current();

var query = "sc_BusinessImpact";

var list = clientContext.get_web().get_lists().getByTitle("Site Information");

clientContext.load(list);

var camlQuery = new SP.CamlQuery();

camlQuery.set_viewXml(query);

var listItems = list.getItems(camlQuery);

clientContext.load(listItems);

clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args) {

var listItemInfo;

var listItemEnumerator = listItems.getEnumerator();

while (listItemEnumerator.moveNext()) {

listItemInfo = listItemEnumerator.get_current().get_item('SC_METADATA_VALUE');

var pageTitle = $('#pageTitle')[0].innerHTML;

if (pageTitle.indexOf("img") > -1) {

classified = true;

}

else {

var siteClassification = listItemInfo;

if (siteClassification == "HBI") {

var img = $("");

$('#pageTitle').prepend(img);

classified = true;

}

else if (siteClassification == "MBI") {

var img = $("");

$('#pageTitle').prepend(img);

classified = true;

}

else if (siteClassification == "LBI") {

var img = $("");

$('#pageTitle').prepend(img);

classified = true;

}

}

}

}));

}

  替代方法

  您可以使用OfficeDevPnP Core中ObjectPropertyBagEntry.cs文件中的扩展方法Web.AddIndexedPropertyBagKey将分类值存储在一个网站属性包中,而不是一个列表。此方法使属性包可抓取或可搜索。

  另见

  最佳实践:内容管理CMS

  phpcms 这个内容管理系统的特点是系统要求非常简单,性能和灵活性很高。 phpcms既适用于小型个人网站,也适用于复杂、大流量的通用网站。 phpcms 不仅仅是一个内容管理系统,它还是一个模板引擎,一个应用程序框架。 phpcms简化了许多维护复杂网站的任务。 phpcms 自动更新网站 地图(站点地图)并具有菜单集中管理,集成的全文搜索引擎。它将网站的布局与网站的内容完全分开。

  

  【许可协议】GNU通用公共许可证(GPL)

  查看全部【

  

  内容管理cms]分类项目

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线