コード例 #1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// DeleteRule runs when the Delete button for a specified rule is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///     [jbrinkman]	5/28/2007  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void DeleteRule(object source, DataListCommandEventArgs e)
        {
            //Get the index of the row to delete
            int index = e.Item.ItemIndex;

            //Remove the rule from the rules collection
            Rules.RemoveAt(index);
            try
            {
                //Save the new collection
                RequestFilterSettings.Save(Rules);
            }
            catch (UnauthorizedAccessException exc)
            {
                Logger.Debug(exc);

                lblErr.InnerText = Localization.GetString("unauthorized", LocalResourceFile);
                lblErr.Visible   = true;
                //This forces the system to reload the settings from DotNetNuke.Config
                //since we have already deleted the entry from the Rules list.
                Rules = null;
            }

            //Rebind the collection
            BindRules();
        }
コード例 #2
0
        /// <summary>
        /// SaveRule runs when the Save button is clicked.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// The Save button is displayed for a specific request filter rule
        /// when the user enters the edit mode.
        /// </remarks>
        /// <history>
        ///     [jbrinkman]	5/28/2007  Created
        /// </history>
        protected void SaveRule(object source, DataListCommandEventArgs e)
        {
            //Get the index of the row to save
            int index = rptRules.EditItemIndex;

            RequestFilterRule rule = Rules[index];
            var txtServerVar       = (TextBox)e.Item.FindControl("txtServerVar");
            var txtValue           = (TextBox)e.Item.FindControl("txtValue");
            var txtLocation        = (TextBox)e.Item.FindControl("txtLocation");
            var ddlOperator        = (DnnComboBox)e.Item.FindControl("ddlOperator");
            var ddlAction          = (DnnComboBox)e.Item.FindControl("ddlAction");

            if (!String.IsNullOrEmpty(txtServerVar.Text) && !String.IsNullOrEmpty(txtValue.Text))
            {
                rule.ServerVariable = txtServerVar.Text;
                rule.Location       = txtLocation.Text;
                rule.Operator       = (RequestFilterOperatorType)Enum.Parse(typeof(RequestFilterOperatorType), ddlOperator.SelectedValue);
                rule.Action         = (RequestFilterRuleType)Enum.Parse(typeof(RequestFilterRuleType), ddlAction.SelectedValue);

                //A rule value may be a semicolon delimited list of values.  So we need to use a helper function to
                //parse the list.  If this is a regex, then only one value is supported.
                rule.SetValues(txtValue.Text, rule.Operator);

                //Save the modified collection
                RequestFilterSettings.Save(Rules);
            }
            else
            {
                if (AddMode)
                {
                    //Remove the temporary added row
                    Rules.RemoveAt(Rules.Count - 1);
                }
            }
            AddMode = false;

            //Reset Edit Index
            rptRules.EditItemIndex = -1;
            BindRules();
        }