Just Code‎ > ‎

EPiServer Plugin web usercontrol, with access control who should be able to see it

posted Jan 17, 2010, 2:34 PM by Peter Henell   [ updated Jan 18, 2010, 6:25 AM ]
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Web.WebControls;
using EPiServer.PlugIn;

namespace EPiServer.Labs.Units
{ [GuiPlugIn(Area = PlugInArea.EditPanel, DisplayName = "Peters plugin", Description = "Ett litet plugin", Url = "~/Labs/Units/TestPlugin.ascx", SortIndex = 1000)] public partial class TestPlugin : EPiServer.UserControlBase, ICustomPlugInLoader
{ /// <summary> /// Visar detta plugin om administratören har konfiguererat att aktuell inloggad användare har rätt att se pluginet. /// Administration av detta görs i Admin -> Config -> Plugin Manager -> templates5(detta är projektnamnet) /// </summary> public TestPlugin() { PlugInSettings.AutoPopulate(this); } protected void Page_Load(object sender, EventArgs e) { DataBind(); } [PlugInProperty(AdminControl = typeof(TextBox),
AdminControlValue = "Text",
DisplayName="Tillåtna roller för detta plugin")] public string AllowedRolesString { get; set; } #region ICustomPlugInLoader Members public string[] AllowedRoles
{ get { if (string.IsNullOrEmpty(AllowedRolesString)) return new string[0]; else return AllowedRolesString.Split(','); } } public PlugInDescriptor[] List() { foreach (string role in AllowedRoles) { foreach (string userRole in EPiServer.Security.PrincipalInfo.Current.RoleList) { if (role == userRole) return new PlugInDescriptor[1] { new PlugInDescriptor(0, typeof(TestPlugin)) }; } } return new PlugInDescriptor[0]; } #endregion } }
Comments