在 Kentico 12 上,页面内的属性 Security 不像以前的版本Kentico 11 - Interface Access那样具有 Access 字段。
我需要提供此功能,因此我正在考虑使用这样的覆盖 OnAuthentication 方法:
protected override void OnAuthentication(AuthenticationContext filterContext)
{
var isAuthenticated = filterContext.Principal.Identity.IsAuthenticated;
var routePath = filterContext.HttpContext.Request.Path;
var page = DocumentHelper.GetDocuments().Path(routePath).FirstOrDefault();
var allowAccess = (page.HasSecureProperty && isAuthenticated) || !page.HasSecureProperty;
if (allowAccess)
{
base.OnAuthentication(filterContext);
}
else
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(new { controller = "Account", action = "Signin" })
);
}
}
HasSecureProperty 将是 kentico 页面中管理员或编辑用户可以在管理面板上设置的属性。我计划使用自定义表创建此属性,并在页面上为用户创建一个界面。
CMS_Tree 上的 IsSecureNode 字段似乎是我需要的属性,并且在以前的版本中使用过,但我找不到在新管理面板上设置的方法。
是否有其他解决方案允许用户在页面上设置身份验证?我担心性能,因为每个动作都会调用这个方法。谢谢你。