Acesso negado ao HttpListener
Estou escrevendo um servidor HTTP em c #.
Quando tento executar a funçãoHttpListener.Start()
Eu recebo umHttpListenerException
dizendo
"Acesso negado".
Quando executo o aplicativo no modo de administrador no Windows 7, ele funciona bem.
Posso fazê-lo funcionar sem o modo de administrador? se sim como? Caso contrário, como posso fazer com que o aplicativo mude para o modo de administrador depois de começar a executar?
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;
}
}
}
}
}