Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using CMS.Helpers;
- using CMS.Membership;
- using CMS.SiteProvider;
- using Kentico.Content.Web.Mvc;
- using Kentico.Web.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Security.Principal;
- using System.Web;
- using System.Web.Mvc;
- namespace KMVCHelper
- {
- public class EnvironmentHelper
- {
- public static bool PreviewEnabled
- {
- get
- {
- try
- {
- return HttpContext.Current.Kentico().Preview().Enabled;
- } catch(InvalidOperationException)
- {
- // This occurs only on the Owin Authentication calls due to the Dynamic route handler
- return false;
- }
- }
- }
- public static string CurrentCulture
- {
- get
- {
- try {
- return HttpContext.Current.Kentico().Preview().CultureName;
- }
- catch (InvalidOperationException)
- {
- // This occurs only on the Owin Authentication calls due to the Dynamic route handler
- return "en-US";
- }
- }
- }
- public static string CurrentSiteName
- {
- get
- {
- return CacheHelper.Cache<string>(cs =>
- {
- // do a lookup based on the URL
- string SiteName = SiteInfoProvider.GetSites().WhereLike("SitePresentationUrl", "%" + HttpContext.Current.Request.Url.Host + "%").FirstOrDefault()?.SiteName;
- if (cs.Cached)
- {
- cs.CacheDependency = CacheHelper.GetCacheDependency("cms.site|byname|" + SiteName);
- }
- return SiteName;
- }, new CacheSettings(1440, "GetSiteFromUrl", HttpContext.Current.Request.Url.Host));
- }
- }
- public static UserInfo AuthenticatedUser(IPrincipal User)
- {
- string Username = (User != null && User.Identity != null ? User.Identity.Name : "public");
- return CacheHelper.Cache<UserInfo>(cs =>
- {
- return UserInfoProvider.GetUserInfo(Username);
- }, new CacheSettings(CacheHelper.CacheMinutes(EnvironmentHelper.CurrentSiteName), "AuthenticatedUser", Username));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement