示例#1
0
        private void aclApply_Click(object sender, EventArgs e)
        {
            string urlPrefix = (this.aclSsl.Checked ? Uri.UriSchemeHttps : Uri.UriSchemeHttp) + "://" + this.aclHostname.Text;
            ushort port;

            if (!string.IsNullOrEmpty(this.aclPort.Text))
            {
                port = ushort.Parse(this.aclPort.Text);
            }
            else
            {
                port = this.aclSsl.Checked ? (ushort)443 : (ushort)80;
            }
            urlPrefix += ":" + port.ToString();
            string path = this.aclPath.Text;

            if (string.IsNullOrEmpty(path) || path[0] != '/')
            {
                path = '/' + path;
            }
            if (path[path.Length - 1] != '/')
            {
                path += '/';
            }
            urlPrefix += path;
            string sddl = "D:";

            foreach (string account in this.aclAccounts.Items)
            {
                SecurityIdentifier sid = new NTAccount(account).Translate(typeof(SecurityIdentifier)) as SecurityIdentifier;
                sddl += "(A;;GX;;;" + sid.Value + ")";
            }
            bool deleted = false;

            if (aclEditedEntry != null)
            {
                try
                {
                    aclEditedEntry.Delete();
                    deleted = true;
                }
                catch (Win32Exception exception)
                {
                    DialogResult result = MessageBox.Show("An error occurred while attempting to perform the requested change. The error message was:\r\n\r\n" + exception.Message, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                    if (result == DialogResult.Abort)
                    {
                        Reload();
                    }
                    if (result != DialogResult.Ignore)
                    {
                        return;
                    }
                }
            }
            HttpConfigUrlAclEntry entry = new HttpConfigUrlAclEntry(urlPrefix, sddl);

            try
            {
                entry.Create();
            }
            catch (Win32Exception exception)
            {
                DialogResult result = MessageBox.Show("An error occurred while attempting to perform the requested change. The error message was:\r\n\r\n" + exception.Message, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                if (result == DialogResult.Abort)
                {
                    Reload();
                }
                if (result != DialogResult.Ignore)
                {
                    return;
                }
                if (deleted && aclEditedEntry != null)
                {
                    try
                    {
                        aclEditedEntry.Create();
                    }
                    catch (Win32Exception)
                    {
                    }
                }
            }
            aclEditedEntry = null;
            Reload();
        }