public static void AddListener(HttpListener listener)
        {
            ArrayList arrayList = new ArrayList();

            try
            {
                Hashtable obj = EndPointManager.ip_to_endpoints;
                lock (obj)
                {
                    foreach (string text in listener.Prefixes)
                    {
                        EndPointManager.AddPrefixInternal(text, listener);
                        arrayList.Add(text);
                    }
                }
            }
            catch
            {
                foreach (object obj2 in arrayList)
                {
                    string prefix = (string)obj2;
                    EndPointManager.RemovePrefix(prefix, listener);
                }
                throw;
            }
        }
Example #2
0
        /// <summary>Removes the specified Uniform Resource Identifier (URI) from the list of prefixes handled by the <see cref="T:System.Net.HttpListener" /> object.</summary>
        /// <returns>true if the <paramref name="uriPrefix" /> was found in the <see cref="T:System.Net.HttpListenerPrefixCollection" /> and removed; otherwise false.</returns>
        /// <param name="uriPrefix">A <see cref="T:System.String" /> that contains the URI prefix to remove.</param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="uriPrefix" /> is null.</exception>
        /// <exception cref="T:System.Net.HttpListenerException">A Windows function call failed. To determine the cause of the exception, check the exception's error code.</exception>
        /// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.HttpListener" /> associated with this collection is closed.</exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
        /// </PermissionSet>
        public bool Remove(string uriPrefix)
        {
            this.listener.CheckDisposed();
            if (uriPrefix == null)
            {
                throw new ArgumentNullException("uriPrefix");
            }
            bool flag = this.prefixes.Remove(uriPrefix);

            if (flag && this.listener.IsListening)
            {
                EndPointManager.RemovePrefix(uriPrefix, this.listener);
            }
            return(flag);
        }
Example #3
0
        public bool Remove(string uriPrefix)
        {
            listener.CheckDisposed();
            if (uriPrefix == null)
            {
                throw new ArgumentNullException("uriPrefix");
            }

            bool result = prefixes.Remove(uriPrefix);

            if (result && listener.IsListening)
            {
                EndPointManager.RemovePrefix(uriPrefix, listener);
            }

            return(result);
        }
Example #4
0
        /// <summary>
        /// Removes the specified URI prefix.
        /// </summary>
        /// <param name="uriPrefix">The URI prefix.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">uriPrefix</exception>
        public bool Remove(string uriPrefix)
        {
            _listener.CheckDisposed();
            if (uriPrefix == null)
            {
                throw new ArgumentNullException(nameof(uriPrefix));
            }

            var result = _prefixes.Remove(uriPrefix);

            if (result && _listener.IsListening)
            {
                EndPointManager.RemovePrefix(uriPrefix, _listener);
            }

            return(result);
        }