System.Security.Permissions.PrincipalPermission.Demand C# (CSharp) Method

Demand() public method

public Demand ( ) : void
return void
        public void Demand()
        {
            IPrincipal principal = Thread.CurrentPrincipal;
            if (principal == null)
                throw new SecurityException(SR.Security_PrincipalPermission);
            if (_idArray == null)
                return;

            // A demand passes when the grant satisfies all entries.
            foreach (IDRole idRole in _idArray)
            {
                // If the demand is authenticated, we need to check the identity and role
                if (!idRole.Authenticated)
                {
                    return;
                }
                else if (principal.Identity.IsAuthenticated &&
                         (idRole.ID == null || string.Equals(principal.Identity.Name, idRole.ID, StringComparison.OrdinalIgnoreCase)))
                {
                    if (idRole.Role == null || principal.IsInRole(idRole.Role))
                        return;
                }
            }

            throw new SecurityException(SR.Security_PrincipalPermission);
        }

Usage Example

        protected void Page_Load(object sender, EventArgs e)
        {
            SetDefaultControls("btnGetRight", "");
              PrincipalPermission permReg = new PrincipalPermission(Context.User.Identity.Name, "Registered");
              permReg.Demand();

              if (!Page.IsPostBack)
              {
            IOrganisationService srvOrg = ServiceFactory.GetOrganisationService();

            //megnézzük hogy volt e szervezet kiválasztva (van e selectedOrgId)
            string selectedOrgId = Request["selectedOrgId"];

            if (selectedOrgId != null)
            {
              //lekérdezzük a kiválasztott szervezet adatait
              Organisation org = srvOrg.OrganisationSelect(new Guid(selectedOrgId));

              txtOrgInstitution.Text = org.Name;
              lblZipCode.Text = org.PostCode;
              lblTownShip.Text = org.City;
              lblAddress.Text = org.Address;

              lblOrganisationForm.Text = org.Department.IsNull ? "-" : org.Department.ToString();
            }
              }
        }
All Usage Examples Of System.Security.Permissions.PrincipalPermission::Demand