示例#1
0
    /// <summary>
    /// Creates banned ip. Called when the "Create ip" button is pressed.
    /// </summary>
    private bool CreateBannedIp()
    {
        // Create new banned ip object
        BannedIPInfo newIp = new BannedIPInfo();

        // Set the properties
        newIp.IPAddress              = "MyNewIp";
        newIp.IPAddressBanReason     = "Ban reason";
        newIp.IPAddressAllowed       = true;
        newIp.IPAddressAllowOverride = true;
        newIp.IPAddressBanType       = BannedIPInfoProvider.BanControlEnumString(BanControlEnum.AllNonComplete);
        newIp.IPAddressBanEnabled    = true;

        // Save the banned IP
        BannedIPInfoProvider.SetBannedIPInfo(newIp);

        return(true);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Controls initialization
        radBanIP.Text   = GetString("banip.radBanIP");
        radAllowIP.Text = GetString("banip.radAllowIP");

        lblIPAddressBanType.Text    = GetString("banip.IPAddressBanType") + ResHelper.Colon;
        lblIPAddressBanEnabled.Text = GetString("general.enabled") + ResHelper.Colon;
        lblIPAddress.Text           = GetString("banip.IPAddress") + ResHelper.Colon;
        lblIPAddressBanReason.Text  = GetString("banip.IPAddressBanReason") + ResHelper.Colon;

        rfvIPAddress.ErrorMessage      = GetString("banip.IPAddressEmpty");
        lblIPAddressAllowOverride.Text = GetString("banip.IPAddressAllowOverride") + ResHelper.Colon;

        if (!RequestHelper.IsPostBack())
        {
            // Add list items to ban type drop down list
            ControlsHelper.FillListControlWithEnum <BanControlEnum>(drpIPAddressBanType, "banip.bantype", useStringRepresentation: true);
            drpIPAddressBanType.SelectedValue = BannedIPInfoProvider.BanControlEnumString(BanControlEnum.AllNonComplete);
        }

        string currentBannedIP = GetString("banip.NewItemCaption");

        // Get bannedIP id from querystring
        itemid = QueryHelper.GetInteger("itemid", 0);
        if (itemid > 0)
        {
            BannedIPInfo bannedIPObj = BannedIPInfoProvider.GetBannedIPInfo(itemid);
            EditedObject = bannedIPObj;

            if (bannedIPObj != null)
            {
                //Check whether the item truly belogs to specified site
                if (((SiteID > 0) && (bannedIPObj.IPAddressSiteID != SiteID)) ||
                    ((SelectedSiteID > 0) && (bannedIPObj.IPAddressSiteID != SelectedSiteID)))
                {
                    RedirectToAccessDenied(GetString("banip.invaliditem"));
                }

                currentBannedIP = bannedIPObj.IPAddress;

                // Add site info to breadcrumbs
                if (SiteID == 0)
                {
                    if (bannedIPObj.IPAddressSiteID == 0)
                    {
                        currentBannedIP += " (global)";
                        radAllowIP.Text  = GetString("banip.radAllowIPglobal");

                        plcIPOveride.Visible = true;
                    }
                    else
                    {
                        SiteInfo si = SiteInfoProvider.GetSiteInfo(bannedIPObj.IPAddressSiteID);
                        if (si != null)
                        {
                            currentBannedIP += " (" + si.DisplayName + ")";
                        }
                    }
                }

                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(bannedIPObj);

                    // Show that the bannedIP was created or updated successfully
                    if ((QueryHelper.GetInteger("saved", 0) == 1) && !URLHelper.IsPostback())
                    {
                        ShowChangesSaved();
                    }
                }
            }
        }

        // Initializes page title control
        SetBreadcrumb(0, GetString("banip.listHeaderCaption"), ResolveUrl("BannedIP_List.aspx?siteId=" + SiteID + "&selectedsiteid=" + SelectedSiteID), null, null);
        SetBreadcrumb(1, currentBannedIP, null, null, null);

        // Add info about selected site in Site manager for new item
        if ((SiteID == 0) && (itemid == 0))
        {
            if (SelectedSiteID > 0)
            {
                // Site banned IP
                SiteInfo si = SiteInfoProvider.GetSiteInfo(SelectedSiteID);
                if (si != null)
                {
                    SetBreadcrumb(1, currentBannedIP + " (" + si.DisplayName + ")", null, null, null);
                }
            }
            else
            {
                // Global banned IP
                SetBreadcrumb(1, currentBannedIP + " (global)", null, null, null);

                radAllowIP.Text = GetString("banip.radAllowIPglobal");

                plcIPOveride.Visible = true;
            }
        }

        // Different header and icon if it is new item
        if (itemid <= 0)
        {
            SetTitle(GetString("banip.newHeaderCaption"));
        }
    }