title: HttpListener Access Denied
body: <p>I am writing an HTTP server in C#.</p>
  
  <p>When I try to execute the function <code>HttpListener.Start()</code> I get an <code>HttpListenerException</code> saying </p>
  
  <blockquote>
    <p>"Access Denied".</p>
  </blockquote>
  
  <p>When I run the app in admin mode in windows 7 it works fine.</p>
  
  <p>Can I make it run without admin mode? if yes how?
  If not how can I make the app change to admin mode after start running?</p>
  
  <pre><code>using System;
  using System.Net;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          private HttpListener httpListener = null;
  
          static void Main(string[] args)
          {
              Program p = new Program();
              p.Server();
          }
  
          public void Server()
          {
              this.httpListener = new HttpListener();
  
              if (httpListener.IsListening)
                  throw new InvalidOperationException("Server is currently running.");
  
              httpListener.Prefixes.Clear();
              httpListener.Prefixes.Add("http://*:4444/");
  
              try
              {
                  httpListener.Start(); //Throws Exception
              }
              catch (HttpListenerException ex)
              {
                  if (ex.Message.Contains("Access is denied"))
                  {
                      return;
                  }
                  else
                  {
                      throw;
                  }
              }
          }
      }
  }
  </code></pre>