Пример #1
0
        protected void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            AnonymousIdentificationModule.ClearAnonymousIdentifier();

            try
            {
                var userId    = WebCommon.GetUserId();
                var menuBll   = new SiteMenus();
                var accessIds = new List <string>();
                accessIds.Add(userId.ToString());
                Task[] tasks = new Task[3];
                tasks[0] = Task.Factory.StartNew(() =>
                {
                    var roleIds = new SiteRoles().GetAspnetRoleIds(Roles.GetRolesForUser());
                    foreach (var item in roleIds)
                    {
                        accessIds.Add(item.ToString());
                    }
                });
                var userProfileInfo = new UserProfileInfo();
                tasks[1] = Task.Factory.StartNew(() =>
                {
                    var fuInfo = new FeatureUser().GetModel(userId, "UserProfile");
                    if (fuInfo != null)
                    {
                        userProfileInfo.SiteCode    = fuInfo.SiteCode;
                        userProfileInfo.SiteTitle   = fuInfo.SiteTitle;
                        userProfileInfo.SiteLogo    = string.IsNullOrWhiteSpace(fuInfo.SiteLogo) ? "" : WebCommon.GetSiteAppName() + fuInfo.SiteLogo;
                        userProfileInfo.CultureName = fuInfo.CultureName;
                    }
                });
                IList <SiteMenusInfo> maList = new List <SiteMenusInfo>();
                tasks[2] = Task.Factory.StartNew(() =>
                {
                    maList = menuBll.GetMenusAccess(Membership.ApplicationName, accessIds.ToArray(), User.IsInRole("Administrators"));
                });
                Task.WaitAll(tasks);

                var Profile = new CustomProfileCommon();
                Profile.UserMenus = JsonConvert.SerializeObject(maList);
                Profile.UserInfo  = JsonConvert.SerializeObject(userProfileInfo);

                Profile.Save();
            }
            catch { }
        }
Пример #2
0
        private void Bind()
        {
            Control ctl = this.LoadControl("~/WebUserControls/UCMenu.ascx");

            ctl.ID = "UCMenu";
            phUc.Controls.Add(ctl);

            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                var Profile         = new CustomProfileCommon();
                var userProfileInfo = JsonConvert.DeserializeObject <UserProfileInfo>(Profile.UserInfo);
                if (userProfileInfo != null)
                {
                    lbSiteTitle.InnerText = userProfileInfo.SiteTitle;
                    if (!string.IsNullOrWhiteSpace(userProfileInfo.SiteLogo) && File.Exists(userProfileInfo.SiteLogo.Replace(WebCommon.GetSiteAppName(), "~")))
                    {
                        imgLogo.Src     = userProfileInfo.SiteLogo;
                        imgLogo.Visible = true;
                    }
                    LoginStatus lsUser = lvUser.FindControl("lsUser") as LoginStatus;
                    if (!string.IsNullOrWhiteSpace(userProfileInfo.CultureName) && userProfileInfo.CultureName.ToLower() == "en-us")
                    {
                        lsUser.LogoutText = "[Sign Out]";
                        LoginName lnUser = lvUser.FindControl("lnUser") as LoginName;
                        lnUser.FormatString = "Welcome,{0}";
                    }
                    lbAppId.InnerText = userProfileInfo.SiteCode;
                    if (userProfileInfo.SiteCode == Auth.AppCode)
                    {
                        lsUser.Visible = false;
                        Literal ltrRegister = lvUser.FindControl("ltrRegister") as Literal;
                        ltrRegister.Text = string.Format("<a href=\"{0}/login.html\" style=\"color:#FFF;\">[登录]</a><a href=\"{0}/register.html\" style=\"color:#FFF;\">[注册]</a>", WebCommon.GetSiteAppName().TrimEnd('/'));
                    }
                }
            }
        }