コード例 #1
0
ファイル: Auth.cs プロジェクト: qq283335746/MyContentSystem
        public void CreateSearchItem(ref StringBuilder sqlWhere, ref ParamsHelper parms)
        {
            if (HttpContext.Current.User.IsInRole("Administrators"))
            {
                return;
            }

            if (sqlWhere == null)
            {
                sqlWhere = new StringBuilder(500);
            }
            if (parms == null)
            {
                parms = new ParamsHelper();
            }

            CustomProfileCommon Profile = new CustomProfileCommon();
            var upi = JsonConvert.DeserializeObject <UserProfileInfo>(Profile.UserInfo);

            sqlWhere.Append("and AppCode = @AppCode ");
            var parm = new SqlParameter("@AppCode", SqlDbType.Char, 6);

            parm.Value = upi.SiteCode;
            parms.Add(parm);

            if (upi.SiteCode == "000000")
            {
                sqlWhere.Append("and UserId = @UserId ");
                parm       = new SqlParameter("@UserId", SqlDbType.UniqueIdentifier);
                parm.Value = WebCommon.GetUserId();
                parms.Add(parm);
            }
        }
コード例 #2
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();
        }
コード例 #3
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);
        }