Example #1
0
    protected void SetUser()
    {
        if (User.Identity.IsAuthenticated && user == null)
        {
            user = Membership.GetUser(Page.User.Identity.Name);
            SetCurrentAccountVariables(user);
        }


        DataBindMainMenu();

        if (!CheckIfUserHasPermissionsToSeeThisPage())
        {
            CurrentUrlHash = null;
            Response.Redirect("~/" + CurrentUrlHash.Replace("#", "").Replace(" ", "") + ".aspx");
        }
    }
Example #2
0
    /// <summary>
    /// Loadig all controls for current page
    /// </summary>
    /// <param name="mustDataBind"></param>
    protected void LoadControls(bool mustDataBind)
    {
        LastLoadedControls = new List <string>();

        CurrentUrlHash = Request.Url.PathAndQuery.Replace("/", "#").Replace(".aspx", "");
        string chekCurrentUrlHash = CurrentUrlHash;

        if (CurrentUrlHash.Contains("?"))
        {
            string[] splitCurrentUrlHash = CurrentUrlHash.Split(new string[] { "?" }, StringSplitOptions.RemoveEmptyEntries);
            chekCurrentUrlHash = splitCurrentUrlHash[0];
        }

        XElement currentMenuItem = XDocument.Load(Server.MapPath("~/App_Data/MainMenu.xml")).Root.Elements().First(el => el.Attribute("path").Value.ToLower().Replace(".aspx", "") == chekCurrentUrlHash.Replace("#", "").ToLower());

        foreach (XElement control in currentMenuItem.Elements()) //load all controns that need to be inside this control
        {
            UserControl    u = (UserControl)LoadControl("Modules/" + control.Attribute("name").Value);
            IXMLDataSource xmlSourceControl = u as IXMLDataSource;



            if (xmlSourceControl != null)                         //check if the control uses xml file as data source
            {
                if (CheckIfXMLDataSourceExists(xmlSourceControl)) //check if the xml data source file exists
                {
                    LastLoadedControls.Add("Modules/" + control.Attribute("name").Value);
                }
            }
            else
            {
                LastLoadedControls.Add("Modules/" + control.Attribute("name").Value);
            }
        }

        LoadUserControls(mustDataBind);
    }