如何在特定页面类型而不是父页面上要求 SSL

How to Require SSL on a specific Page Type but not on the parent page

我想知道 Kentico 是否有 "best practice" 方法来确保 需要 SSL 属性 设置为 在特定页面类型上,没有从父页面继承 属性。

我对此进行了研究并实施了一个可行的解决方案(如下),但我很想知道是否有更好的 "out of the box" 解决方案我可能忽略了。

我们使用 Kentico v8.2 和 ASPX + 门户页面类型。

我们的技术要求

  1. 通过 HTTP 或 HTTPS 提供父列表页面
  2. 仅通过 HTTPS 提供子页面

我们的用例场景

用户浏览了一个列出职位空缺的页面。用户打开包含申请表的特定职位空缺页面。由于该页面是通过安全连接提供的,因此用户有信心将个人详细信息输入申请表。

考虑过的解决方案

我能找到的最接近 "out of the box" 的解决方案是将父列表页面设置为 Require SSL = Yes 然后在子页面上继承它,但是这并不' 满足我们的技术要求,允许通过 HTTP 提供列表页面。

我还决定不在每个子页面上手动设置 Requires SSL = Yes,因为我不想给 CMS 编辑带来这种负担,给他们更多的权限并将其开放给人为错误。

当前解

所以我最终编写了一个自定义事件处理程序来在 Document InsertDocument Update 上设置 Requires SSL 属性事件。

最初我是根据页面类型 (Node.ClassName) 执行此操作的,但将其更改为基于字段值,这样我就可以更轻松地将其应用于其他页面类型,只需添加一个字段而无需重构我的代码和部署 DLL。

[CustomEvents]
public partial class CMSModuleLoader
{
    private class CustomEvents : CMSLoaderAttribute
    {
        public override void Init() { 
            DocumentEvents.Insert.Before += Document_Insert_Before;
            DocumentEvents.Update.Before += Document_Update_Before;
        }

        void Document_Insert_Before(object sender, DocumentEventArgs e)
        {
            SetRequiresSSL(e.Node);
        }

        void Document_Update_Before(object sender, DocumentEventArgs e)
        {
            SetRequiresSSL(e.Node);
        }

        private void SetRequiresSSL(TreeNode node)
        {
            //if RequiresSecureConnection field is equal to true
            if (node.GetBooleanValue("RequiresSecureConnection", false))
            {
                //if Requires SSL is not Yes
                if (node.RequiresSSL != 1)
                {
                    //set Requires SSL
                    node.RequiresSSL = 1;
                }
            }
        }
    }
}

相关网址

如果您在页面类型上使用系统属性,则无需任何自定义即可开箱即用,并且仍可编辑:

  • 打开你的页面类型
  • 添加新字段
  • select 字段类型:页面字段
  • select 组:节点字段
  • select 字段名称:RequiresSSL
  • 输入默认值:1(此类型为 YES)
  • Deselect 编辑表单中的显示字段,因此编辑器不会看到它。

这样,基于此页面类型创建的所有页面都将预装 RequiresSSLselect。而且还是可以调整的。

大卫