【发布时间】:2017-02-02 10:37:45
【问题描述】:
我需要为 umbraco 成员(来自最终成员)存储密码重置令牌。现在我得到的解决方案是创建一个属性并使用它。但问题是这个令牌应该对所有人隐藏。是否有任何干净的方法来隐藏属性(不添加对包的依赖项)?
到目前为止approach 我发现看起来像这样,但我正在寻找更简单的方法来隐藏属性:
public class ApplicationHandler : ApplicationEventHandler
{
public ApplicationHandler()
{
ContentControl.AfterContentControlLoad = new ContentControl.AfterContentControlLoadEventHandler(ContentControl_AfterContentControlLoad);
}
private void ContentControl_AfterContentControlLoad(ContentControl contentControl, ContentControlLoadEventArgs e)
{
int docId = 0;
int.TryParse(HttpContext.Current.Request["id"], out docId);
IContent content = ApplicationContext.Current.Services.ContentService.GetById(docId);
Control ctl = umbraco.presentation.LiveEditing.Utility.FindControl<Control>(delegate(Control c)
{
return c.ClientID.EndsWith("propertyAliasToHide");
}, contentControl.Page);
HideProperty(ctl);
}
private void HideProperty(Control control)
{
if (control != null)
{
Control parent = control.Parent;
if (parent != null)
{
if (parent.Parent != null)
{
if (parent.Parent.Parent != null)
{
parent.Parent.Parent.Visible = false;
}
}
}
}
}
}
【问题讨论】: