/// <summary>Allows this instance to receive incoming requests.</summary>
 /// <exception cref="T:System.Net.HttpListenerException">A Win32 function call failed. Check the exception's <see cref="P:System.Net.HttpListenerException.ErrorCode" /> property to determine the cause of the exception.</exception>
 /// <exception cref="T:System.ObjectDisposedException">This object 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 void Start()
 {
     this.CheckDisposed();
     if (this.listening)
     {
         return;
     }
     EndPointManager.AddListener(this);
     this.listening = true;
 }
        public static void RemoveListener(HttpListener listener)
        {
            Hashtable obj = EndPointManager.ip_to_endpoints;

            lock (obj)
            {
                foreach (string prefix in listener.Prefixes)
                {
                    EndPointManager.RemovePrefixInternal(prefix, listener);
                }
            }
        }
Exemple #3
0
 /// <summary>Adds a Uniform Resource Identifier (URI) prefix to the collection.</summary>
 /// <param name="uriPrefix">A <see cref="T:System.String" /> that identifies the URI information that is compared in incoming requests. The prefix must be terminated with a forward slash ("/").</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="uriPrefix" /> is null.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="uriPrefix" /> does not use the http:// or https:// scheme. These are the only schemes supported for <see cref="T:System.Net.HttpListener" /> objects. -or-<paramref name="uriPrefix" /> is not a correctly formatted URI prefix. Make sure the string is terminated with a "/".</exception>
 /// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.HttpListener" /> associated with this collection is closed.</exception>
 /// <exception cref="T:System.Net.HttpListenerException">A Windows function call failed. Check the exception's <see cref="P:System.Net.HttpListenerException.ErrorCode" /> property to determine the cause of the exception. This exception is thrown if another <see cref="T:System.Net.HttpListener" /> has already added the prefix <paramref name="uriPrefix" />.</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" />
 ///   <IPermission class="System.Net.WebPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 /// </PermissionSet>
 public void Add(string uriPrefix)
 {
     listener.CheckDisposed();
     ListenerPrefix.CheckUri(uriPrefix);
     if (!prefixes.Contains(uriPrefix))
     {
         prefixes.Add(uriPrefix);
         if (listener.IsListening)
         {
             EndPointManager.AddPrefix(uriPrefix, listener);
         }
     }
 }
Exemple #4
0
 /// <summary>Adds a Uniform Resource Identifier (URI) prefix to the collection.</summary>
 /// <param name="uriPrefix">A <see cref="T:System.String" /> that identifies the URI information that is compared in incoming requests. The prefix must be terminated with a forward slash ("/").</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="uriPrefix" /> is null.</exception>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="uriPrefix" /> does not use the http:// or https:// scheme. These are the only schemes supported for <see cref="T:System.Net.HttpListener" /> objects. -or-<paramref name="uriPrefix" /> is not a correctly formatted URI prefix. Make sure the string is terminated with a "/".</exception>
 /// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.HttpListener" /> associated with this collection is closed.</exception>
 /// <exception cref="T:System.Net.HttpListenerException">A Windows function call failed. Check the exception's <see cref="P:System.Net.HttpListenerException.ErrorCode" /> property to determine the cause of the exception. This exception is thrown if another <see cref="T:System.Net.HttpListener" /> has already added the prefix <paramref name="uriPrefix" />.</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" />
 ///   <IPermission class="System.Net.WebPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 /// </PermissionSet>
 public void Add(string uriPrefix)
 {
     this.listener.CheckDisposed();
     ListenerPrefix.CheckUri(uriPrefix);
     if (this.prefixes.Contains(uriPrefix))
     {
         return;
     }
     this.prefixes.Add(uriPrefix);
     if (this.listener.IsListening)
     {
         EndPointManager.AddPrefix(uriPrefix, this.listener);
     }
 }
Exemple #5
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);
        }
        private static void AddPrefixInternal(string p, HttpListener listener)
        {
            ListenerPrefix listenerPrefix = new ListenerPrefix(p);

            if (listenerPrefix.Path.IndexOf('%') != -1)
            {
                throw new HttpListenerException(400, "Invalid path.");
            }
            if (listenerPrefix.Path.IndexOf("//") != -1)
            {
                throw new HttpListenerException(400, "Invalid path.");
            }
            EndPointListener eplistener = EndPointManager.GetEPListener(IPAddress.Any, listenerPrefix.Port, listener, listenerPrefix.Secure);

            eplistener.AddPrefix(listenerPrefix, listener);
        }
        private static void RemovePrefixInternal(string prefix, HttpListener listener)
        {
            ListenerPrefix listenerPrefix = new ListenerPrefix(prefix);

            if (listenerPrefix.Path.IndexOf('%') != -1)
            {
                return;
            }
            if (listenerPrefix.Path.IndexOf("//") != -1)
            {
                return;
            }
            EndPointListener eplistener = EndPointManager.GetEPListener(IPAddress.Any, listenerPrefix.Port, listener, listenerPrefix.Secure);

            eplistener.RemovePrefix(listenerPrefix, listener);
        }
 private void CheckIfRemove()
 {
     if (this.prefixes.Count > 0)
     {
         return;
     }
     if (this.unhandled != null && this.unhandled.Count > 0)
     {
         return;
     }
     if (this.all != null && this.all.Count > 0)
     {
         return;
     }
     EndPointManager.RemoveEndPoint(this, this.endpoint);
 }
Exemple #9
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);
        }
Exemple #10
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);
        }
Exemple #11
0
        void CheckIfRemove()
        {
            if (prefixes.Count > 0)
            {
                return;
            }

            if (unhandled != null && unhandled.Count > 0)
            {
                return;
            }

            if (all != null && all.Count > 0)
            {
                return;
            }

            EndPointManager.RemoveEndPoint(this, endpoint);
        }
Exemple #12
0
        void CheckIfRemove()
        {
            if (prefixes.Count > 0)
            {
                return;
            }

            ArrayList list = unhandled;

            if (list != null && list.Count > 0)
            {
                return;
            }

            list = all;
            if (list != null && list.Count > 0)
            {
                return;
            }

            EndPointManager.RemoveEndPoint(this, endpoint);
        }
Exemple #13
0
        private void CheckIfRemove()
        {
            if (_prefixes.Count > 0)
            {
                return;
            }

            var list = _unhandled;

            if (list != null && list.Count > 0)
            {
                return;
            }

            list = _all;
            if (list != null && list.Count > 0)
            {
                return;
            }

            EndPointManager.RemoveEndPoint(this, _endpoint);
        }
Exemple #14
0
 void Close(bool force)
 {
     CheckDisposed();
     EndPointManager.RemoveListener(this);
     Cleanup(force);
 }