public static bool HasAnonymousAccessCacheFunction(string requestedUrl) { IViewElementRoleService viewElementRoleService = ServiceBase.DependencyInjectionFactory.CreateInjectionInstance <IViewElementRoleService>(); //if (appBase.ViewElementsGrantedToAnonymousUser == null) //{ //var userProfileService = ServiceBase.DependencyInjectionFactory.CreateInjectionInstance<IUserProfileService>(); // var viewElementRoleService = ServiceBase.DependencyInjectionFactory.CreateInjectionInstance<IViewElementRoleService>(); // var userProfile = UserProfileService.Filter(entity => entity.Id.Equals(2)).FirstOrDefault(); // 2 => Anonymous userProfile var viewElements = viewElementRoleService.GetViewElementGrantedToUserByUserId(2); appBase.ViewElementsGrantedToAnonymousUser = new UserViewElement { UserId = 2, ViewElements = viewElements }; //} var elementWithAccess = appBase.ViewElementsGrantedToAnonymousUser.ViewElements.FirstOrDefault(element => HasRequestedUrlAccessInViewElement(element, requestedUrl)); if (elementWithAccess == null) { return(false); } else { return(true); } }
public bool HasRoleAccess(int userId, string uniqueName, string urlParam = "") { UserViewElement currentUser = null; var viewElements = ViewElementRoleService.GetViewElementGrantedToUserByUserId(userId); currentUser = new UserViewElement { UserId = userId, ViewElements = viewElements }; appBase.ViewElementsGrantedToUser.TryAdd(userId, currentUser); var accessVElement = currentUser.ViewElements; foreach (var item in accessVElement) { if (!string.IsNullOrEmpty(uniqueName)) { if (HasRequestedUrlAccessInViewElement(item, uniqueName)) { return(true); } } } return(false); }