新用户登录时刷新 sectionTree

Refresh sectionTree on new user login

我有一个分区树,它根据当前登录用户的用户类型而变化。

问题是,如果我从后台注销,并使用较低 UserType 的新用户登录,树不会刷新 - 代码不会重新运行以生成树。

这意味着具有非管理 UserType 的用户可以访问该部分中的管理区域,只要管理员之前已在同一解决方案上登录。

如何在新用户登录时刷新 SectionTree?

更新

protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{

    var sectionApi = new SectionApiController();


    // Root handler
    if (id == Constants.System.Root.ToInvariantString())
    {
        this.RootHandler();
    }
    else if(id.Contains("COUNTRY_") || id.Contains("LEVEL_") )
    {
            var section = new IdConvert(id);

        if ( section.Area.Equals("country") )
        {
            this.FirstLevelHandler(section.Id);
        }
        else if (section.Area.Equals("level"))
        {
            this.GetLevels(section.Id);
        }

        // Render clubs.
        this.ClubHandler();
        // Render levels
        this.LevelHandler();

    } else if(id.Contains("CLUB_"))  {

    }
    else if(id.Contains("SPORTS_")) {
        var Country = new IdConvert(id);
        this.SportsHandler(Country.Id);
    }
    else if (id.Contains("QUESTIONS_"))
    {
        var Country = new IdConvert(id);
        this.QuestionsHandler(Country.Id);

    }


    return this._nodes;
}

树工作正常,它渲染了它应该渲染的东西。但是它不会在新用户登录时刷新。

我正在使用以下内容来检查某人是否 "admin"

public static bool IsAdministrator()
{
    try
    {
        if (_curNewUser == null)
        {
            GetCurrentUser();
        }

        if (_curNewUser.UserType.Alias == "admin")
        {
            return true;
        }
    }
    catch (Exception e) { }

    return false;

}

根据您在用户注销时未清除 _curNewUser 的评论,这就是您看到此问题的原因。

与其保留对 _curNewUser 的引用,不如直接在您的 UserProvider 中使用 UmbracoContext.Current.Security.CurrentUser 内置的 umbraco,这将修复它,如下所示:

public static bool IsAdministrator()
{
    var user = UmbracoContext.Current.Security.CurrentUser;
    return user != null && user.UserType.Alias == "admin";
}

您无需连接到注销事件或类似事件。