コード例 #1
0
ファイル: Auth.cs プロジェクト: qq283335746/MyContentSystem
        public void SetMigrateAnonymous()
        {
            var userId = WebCommon.GetUserId();
            IList <SiteMenusInfo> smis = new List <SiteMenusInfo>();
            UserProfileInfo       upi  = new UserProfileInfo();
            var menuBll = new SiteMenus();

            if (Roles.GetRolesForUser().Length == 0)
            {
                var      guestRole = new SiteRoles().GetAspnetModel(Membership.ApplicationName, "guest");
                string[] accessIds = { guestRole.Id.ToString() };
                smis = menuBll.GetMenusAccess(Membership.ApplicationName, accessIds, false);
                upi  = new UserProfileInfo {
                    SiteCode = AppCode, SiteTitle = GlobalConfig.SiteTitle
                };
            }
            else
            {
                var accessIds = new List <string>();
                accessIds.Add(userId.ToString());
                var roleIds = new SiteRoles().GetAspnetRoleIds(Membership.ApplicationName, Roles.GetRolesForUser());
                foreach (var item in roleIds)
                {
                    accessIds.Add(item.ToString());
                }
                var    isAdmin = HttpContext.Current.User.IsInRole("Administrators");
                Task[] tasks   = new Task[2];
                tasks[0] = Task.Factory.StartNew(() =>
                {
                    var fuInfo = new FeatureUser().GetModel(userId, "UserProfile");
                    if (fuInfo != null)
                    {
                        upi.SiteCode    = fuInfo.SiteCode;
                        upi.SiteTitle   = fuInfo.SiteTitle;
                        upi.SiteLogo    = string.IsNullOrWhiteSpace(fuInfo.SiteLogo) ? "" : WebCommon.GetSiteAppName() + fuInfo.SiteLogo;
                        upi.CultureName = fuInfo.CultureName;
                    }
                });

                tasks[1] = Task.Factory.StartNew(() =>
                {
                    smis = menuBll.GetMenusAccess(Membership.ApplicationName, accessIds.ToArray(), isAdmin);
                });
                Task.WaitAll(tasks);
            }

            var Profile = new CustomProfileCommon();

            Profile.UserMenus = JsonConvert.SerializeObject(smis);
            Profile.UserInfo  = JsonConvert.SerializeObject(upi);

            Profile.Save();
        }
コード例 #2
0
        public static string GetTreeJsonForMenu()
        {
            if (!enableCaching)
            {
                return(GetTreeJson());
            }

            string key  = "Sitemap_" + WebCommon.GetUserId(HttpContext.Current) + "";
            string data = (string)HttpRuntime.Cache[key];

            if (data == null)
            {
                data = GetTreeJson();
                HttpRuntime.Cache.Add(key, data, null, DateTime.Now.AddHours(8), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            }

            return(data);
        }
コード例 #3
0
        public override SiteMapNode FindSiteMapNode(string rawUrl)
        {
            XElement currNode = null;
            var      id       = Guid.Empty;

            if (rawUrl.IndexOf('?') > -1)
            {
                Guid.TryParse(WebCommon.GetQueryStringByKey(rawUrl, "Id"), out id);
            }
            if (!id.Equals(Guid.Empty))
            {
                currNode = root.Descendants().First(x => x.Attribute("Id").Value == id.ToString());
            }
            else
            {
                currNode = root.Descendants().First(x => x.Attribute("Url").Value.ToLower().Contains(rawUrl.ToLower()));
            }

            return(new SiteMapNode(this,
                                   currNode.Attribute("Id").Value,
                                   currNode.Attribute("Url").Value,
                                   currNode.Attribute("Title").Value,
                                   currNode.Attribute("Description").Value));
        }